Skip to content

Commit

Permalink
DO deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Jan 3, 2024
1 parent e26a674 commit 6a54be4
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy

on:
push:
branches: master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: crane auth login
shell: bash
run: >
nix shell .#crane --command
crane auth login registry.digitalocean.com
--username [email protected]
--password "${{ secrets.DIGITAL_OCEAN }}"
- run: nix build .#container --no-link
- run: nix develop .#deploy --command deploy-chris-martin
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
build:
cabal run site

deploy:
rsync -avz -e 'ssh' out/ chris-martin.org:/var/www/chris-martin.org/

.PHONY: build deploy
.PHONY: build
78 changes: 78 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
inputs = {
"nixos-23.11".url = "github:NixOS/nixpkgs/nixos-23.11";
"nixos-unstable".url = "github:NixOS/nixpkgs/nixos-unstable";
"flake-utils".url = "github:numtide/flake-utils";
};
outputs = inputs@{ self, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
nixpkgs = {
"nixos-23.11" = import inputs."nixos-23.11" { inherit system; };
"nixos-unstable" = import inputs."nixos-unstable" { inherit system; };
};
pkgs = nixpkgs."nixos-23.11";
inherit (pkgs) runCommand crane;
inherit (pkgs.lib) fold composeExtensions concatMap attrValues;
inherit (pkgs.haskell.lib) justStaticExecutables;

combineOverrides = old:
fold composeExtensions (old.overrides or (_: _: { }));

haskellPackages = pkgs.haskellPackages.override {
overrides = new: old: {
chris-martin-org = new.callPackage ./chris-martin-org.nix {};
};
};

htmlPages = ./out;

container = pkgs.dockerTools.buildLayeredImage {
name = "chris-martin-org";
contents = [ pkgs.busybox htmlPages ];
config = {
Cmd = [ "${pkgs.busybox}/bin/busybox" "httpd" "-f" "-h" "${htmlPages}" ];
ExposedPorts."80/tcp" = { };
};
};

deploy = pkgs.writeShellApplication {
name = "deploy-chris-martin";
runtimeInputs = [ crane ];
text = ''
cleanup() {
rm -rf "$tmp"
}
trap cleanup EXIT
tmp="$(mktemp -d)"
nix build .#container --out-link "$tmp/container.tar.gz"
gunzip --force "$tmp/container.tar.gz" > "$tmp/container.tar"
crane push "$tmp/container.tar" registry.digitalocean.com/iowa/chris-martin:latest
'';
};

in {
packages = { inherit container htmlPages crane; };
devShells.deploy = pkgs.mkShell { packages = [ deploy ]; };
}
);
}
12 changes: 0 additions & 12 deletions shell.nix

This file was deleted.

0 comments on commit 6a54be4

Please sign in to comment.