Skip to content

Commit

Permalink
[#] Build docker image using nix instead of github action
Browse files Browse the repository at this point in the history
  • Loading branch information
nykma committed May 16, 2024
1 parent f930093 commit 4e94232
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 107 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/binary.yaml

This file was deleted.

20 changes: 17 additions & 3 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Building package
run: nix build -v -L
- name: Build docker
run: nix bundle --bundler 'github:NixOS/bundlers#toDockerImage' .
run: nix build '.#main'
- name: Build docker image
run: |
nix build '.#docker'
ls -lah $(readlink ./result)
docker load -i ./result
- name: Login to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Retag and push
if: github.repository == 'nextdotid/relation_server'
run: |
docker tag nextdotid/relation_server:latest ghcr.io/${{ github.repository }}:${{ github.ref_name }}
docker push ghcr.io/${{ github.repository }}:${{ github.ref_name }}
52 changes: 0 additions & 52 deletions .github/workflows/container.yaml

This file was deleted.

7 changes: 6 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# For developemnt use only.
version: "3.8"
services:
relation:
image: nextdotid/relation_server:latest
ports:
- 127.0.0.1:8000:8000
volumes:
- ./config:/app/config:ro
tigergraph:
image: tigergraph/tigergraph:3.9.1
ports:
Expand Down
49 changes: 42 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,51 @@
let
pkgs = import nixpkgs { inherit system; };
naersk-lib = pkgs.callPackage naersk { };
buildInputs = with pkgs; [ openssl pkg-config ];
nativeBuildInputs = with pkgs; [ cargo rustc rustfmt rust-analyzer pre-commit rustPackages.clippy ];
in
{
defaultPackage = naersk-lib.buildPackage {
inherit buildInputs;
buildInputs = with pkgs; [ openssl cacert curl ];
nativeBuildInputs = with pkgs; [ pkg-config cargo rustc rustfmt rustPackages.clippy ];
rustPackage = naersk-lib.buildPackage {
inherit buildInputs nativeBuildInputs;
# China registry mirror
cratesDownloadUrl = "https://crates-io.proxy.ustclug.org";
src = ./.;
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "nextdotid/relation_server";
tag = "latest";
created = "now";
contents = [ rustPackage pkgs.curl pkgs.cacert ];
config = {
Workingdir = "/app";
Cmd = [ "standalone" ];
ExposedPorts = {
"8000/tcp" = {};
};
Volumes = {
"/app/config" = {};
};
Test = [ "CMD" "curl" "-s" "http://127.0.0.1:8000/" ];
Interval = 30000000000; # 30s
Timeout = 10000000000; # 10s
Retries = 3;
Labels = {
"maintainer" = "Nyk Ma <[email protected]>";
"org.opencontainers.image.description" = "RelationService: relation aggregation.";
"org.opencontainers.image.source" = "https://github.com/NextDotID/relation_server";
"org.opencontainers.image.title" = "relation_server";
"org.opencontainers.image.url" = "https://github.com/NextDotID/relation_server";
};
};
};
in {
packages = {
main = rustPackage;
docker = dockerImage;
};
defaultPackage = rustPackage;
devShell = with pkgs; mkShell {
buildInputs = buildInputs ++ nativeBuildInputs;
buildInputs = buildInputs ++
nativeBuildInputs ++
(with pkgs; [ act rust-analyzer pre-commit ]);
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
});
Expand Down
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ clean:
# npm install -g get-graphql-schema
get-schema:
get-graphql-schema https://api-v2.lens.dev/playground > src/upstream/lensv2/schema.graphql

# Build docker image using nix:
build-docker:
nix build '.#docker'
docker load -i ./result
echo 'Image: nextdotid/relation_server:latest'

0 comments on commit 4e94232

Please sign in to comment.