diff --git a/.github/workflows/binary.yaml b/.github/workflows/binary.yaml deleted file mode 100644 index 29c227d..0000000 --- a/.github/workflows/binary.yaml +++ /dev/null @@ -1,44 +0,0 @@ -name: Build binary - -on: - push: - branches: - - '*' - -jobs: - build-binary: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Cache - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Install latest rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - default: true - override: true - - - name: Build - run: | - cargo build --bins --release - strip target/release/lambda - strip target/release/standalone - - - name: Artifact - uses: actions/upload-artifact@v3 - with: - name: release - path: | - target/release/lambda - target/release/standalone diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml index 04873d3..feda424 100644 --- a/.github/workflows/build_nix.yml +++ b/.github/workflows/build_nix.yml @@ -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: ghcr.io + 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 }} diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml deleted file mode 100644 index 22873a9..0000000 --- a/.github/workflows/container.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build container - -on: - push: - branches: - - main - - develop - # DEBUG - - graphdb/tigergraph - -jobs: - build-image: - if: (github.ref_name == 'main' || github.ref_name == 'develop' || github.ref_name == 'graphdb/tigergraph') && github.repository == 'nextdotid/relation_server' - runs-on: ubuntu-latest - env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Log in to Container registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Setup Docker BuildX - uses: docker/setup-buildx-action@v2 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-docker-build-${{ hashFiles('**/Cargo.lock') }} - - name: Extract metadata - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: '.' - push: true - file: Dockerfile - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/docker-compose.yaml b/docker-compose.yaml index 3fae3ba..459c7ba 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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: diff --git a/flake.nix b/flake.nix index 6c5105a..95449ca 100644 --- a/flake.nix +++ b/flake.nix @@ -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 "; + "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; }; }); diff --git a/justfile b/justfile index 7b7baeb..8f120b8 100644 --- a/justfile +++ b/justfile @@ -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'