Skip to content

Commit

Permalink
Merge pull request #307 from Concordium/lma/rust/release_flow
Browse files Browse the repository at this point in the history
Rust release flow
  • Loading branch information
lassemand authored Nov 27, 2024
2 parents 0fac848 + 5c5c6a3 commit 73f7821
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/backend-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
branches: main
paths:
- backend-rust/**
- .github/**
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [ main ]
paths:
- backend-rust/**
- .github/**

env:
RUST_FMT: "nightly-2023-04-01"
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/release-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Release CCDScan Backend

on:
push:
tags:
- ccdscan-backend/*

jobs:
release-docker:
runs-on: ubuntu-latest
environment: release
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: 'concordium'
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Clone repo
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set image tag if correctly formatted
env:
TAG: ${{ github.ref_name }}
run: |
TAG_VERSION=${TAG##ccdscan-backend/}
EXPECTED=$(yq .package.version Cargo.toml)
EXTRACTED="$TAG_VERSION"
if [ ! "$EXPECTED" = "$EXTRACTED" ] ; then
echo "::error::$EXPECTED does not match $EXTRACTED."
exit 1
fi
echo "TAG_VERSION=${TAG_VERSION}" >> $GITHUB_ENV
- name: Check if images exists
run: |
set +e
docker manifest inspect concordium/ccdscan-indexer:$TAG_VERSION
EXITCODE=$?
if [ $EXITCODE -eq "0" ]; then
echo "::error::concordium/ccdscan-indexer:$TAG_VERSION already exists."
exit 1
fi
docker manifest inspect concordium/ccdscan-api:$TAG_VERSION
EXITCODE=$?
if [ $EXITCODE -eq "0" ]; then
echo "::error::concordium/ccdscan-api:$TAG_VERSION already exists."
exit 1
fi
- name: Build indexer docker image
uses: docker/build-push-action@v6
with:
context: backend-rust
file: backend-rust/Dockerfile
tags: concordium/ccdscan-indexer:${{ env.TAG_VERSION }}
push: true
build-args: |
target_binary=ccdscan-indexer
- name: Build api docker image
uses: docker/build-push-action@v6
with:
context: backend-rust
file: backend-rust/Dockerfile
tags: concordium/ccdscan-api:${{ env.TAG_VERSION }}
push: true
build-args: |
target_binary=ccdscan-api
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- ccdscan/*

jobs:
release-base-image:
release-ccdscan:
uses: concordium/.github/.github/workflows/docker-release-workflow.yaml@v1
with:
SERVICE_NAME: "ccdscan"
Expand Down
25 changes: 25 additions & 0 deletions backend-rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG build_image=rust:1.82-bookworm
ARG base_image=debian:bookworm-slim
ARG target_binary
FROM ${build_image} AS build

WORKDIR /usr/app

COPY Cargo.toml Cargo.lock ./
COPY src ./src
COPY concordium-rust-sdk /usr/app/concordium-rust-sdk
COPY .sqlx .sqlx
RUN cargo install sqlx-cli --no-default-features --features "postgres"
RUN cargo build --release --locked


FROM ${base_image}

WORKDIR /usr/app

COPY migrations /usr/app/migrations
COPY --from=build /usr/app/target/release/${target_binary} /usr/bin/
COPY --from=build /usr/local/cargo/bin/sqlx /usr/local/bin/sqlx

RUN chmod +x /usr/bin/${target_binary}
CMD ["/usr/bin/${target_binary}"]

0 comments on commit 73f7821

Please sign in to comment.