diff --git a/.github/workflows/registry.yml b/.github/workflows/registry.yml new file mode 100644 index 00000000..aab129bf --- /dev/null +++ b/.github/workflows/registry.yml @@ -0,0 +1,41 @@ + +name: "Docker Registry Push" +on: + push: + tags: ['*'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v18 + with: + extra_nix_config: | + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + - uses: cachix/cachix-action@v11 + with: + name: fleetbot + signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - run: nix build -L .#ex_fleet_yards_docker + - name: "Import and Push image" + run: | + docker load < result + docker tag exfleetyards:latest ghcr.io/fleetyards/exfleetyards:latest + docker tag exfleetyards:latest ghcr.io/fleetyards/exfleetyards:${{ github.ref_name }} + docker push ghcr.io/fleetyards/exfleetyards:latest + docker push ghcr.io/fleetyards/exfleetyards:${{ github.ref_name }} \ No newline at end of file diff --git a/flake.nix b/flake.nix index e413741b..3b23e8b1 100644 --- a/flake.nix +++ b/flake.nix @@ -36,7 +36,7 @@ nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; - overlays = [ self.overlays.default ]; + overlays = [ self.overlays.default self.overlays.docker ]; }); in { overlays.fleet = final: prev: { @@ -77,10 +77,33 @@ nativeBuildInputs = [ rebar3 ]; }) { }; }; + overlays.docker = final: prev: { + ex_fleet_yards_docker = final.callPackage + ({ lib, ex_fleet_yards, dockerTools, buildEnv }: + dockerTools.buildImage { + name = "ExFleetYards"; + tag = "latest"; + + copyToRoot = buildEnv { + name = "ex_fleet_yards-root"; + paths = [ ex_fleet_yards ]; + pathsToLink = [ "/bin" ]; + }; + + config = { + Entrypoint = [ "/bin/ex_fleet_yards_web" ]; + Cmd = [ "start" ]; + ExposedPorts."4000/tcp" = { }; + Env = [ "FLEETYARDS_CONFIG_PATH=/config/config.exs" ]; + Volumes."/config/" = { }; + }; + }) { }; + }; overlays.default = self.overlays.fleet; packages = forAllSystems (system: { - inherit (nixpkgsFor.${system}) ex_fleet_yards appsignal_nif; + inherit (nixpkgsFor.${system}) + ex_fleet_yards appsignal_nif ex_fleet_yards_docker; default = self.packages.${system}.ex_fleet_yards; });