From 0bbdcfeb3d2b1e1cd528edc6fb31ff668f580aca Mon Sep 17 00:00:00 2001 From: Swanny Date: Fri, 20 Dec 2024 14:24:36 -0500 Subject: [PATCH 1/3] fix: more descriptive name --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2358d64..b22763e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ name = "zenith-builder-example" path = "bin/builder.rs" [[bin]] -name = "integration-test" +name = "transaction-submitter" path = "bin/submit_transaction.rs" [dependencies] From 9972a4e4959a6dfbe8bc70b5fef835e1e480e963 Mon Sep 17 00:00:00 2001 From: Swanny Date: Fri, 20 Dec 2024 14:39:23 -0500 Subject: [PATCH 2/3] feat: dockerfile --- .github/workflows/ecr-cd.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/ecr-cd.yml diff --git a/.github/workflows/ecr-cd.yml b/.github/workflows/ecr-cd.yml deleted file mode 100644 index 1611e98..0000000 --- a/.github/workflows/ecr-cd.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Docker ECR Push - -on: - push: - branches: [main] - tags: - - v** - workflow_dispatch: - - -permissions: - packages: write - contents: read - id-token: write - -# simplest example of using the rust-base action -jobs: - docker-ecr-push: - uses: init4tech/actions/.github/workflows/ecr-build-and-push.yml@main - with: - rust-binary-name: zenith-builder-example - environment: dev - requires-private-deps: true - secrets: - aws-ecr-repository: ${{ secrets.AWS_ECR_REPOSITORY }} - aws-ecr-deployer-role-arn: ${{ secrets.AWS_ECR_DEPLOYER_ROLE_ARN }} - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} From 5c2f9259a3e94c75e6768485775f3355a590fee3 Mon Sep 17 00:00:00 2001 From: Swanny Date: Fri, 20 Dec 2024 14:39:26 -0500 Subject: [PATCH 3/3] feat: dockerfile --- .github/workflows/builder-ecr-cd.yml | 27 +++++++++++++ .../workflows/transaction-sender-ecr-cd.yml | 28 ++++++++++++++ transaction-submitter.Dockerfile | 38 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 .github/workflows/builder-ecr-cd.yml create mode 100644 .github/workflows/transaction-sender-ecr-cd.yml create mode 100644 transaction-submitter.Dockerfile diff --git a/.github/workflows/builder-ecr-cd.yml b/.github/workflows/builder-ecr-cd.yml new file mode 100644 index 0000000..2987df7 --- /dev/null +++ b/.github/workflows/builder-ecr-cd.yml @@ -0,0 +1,27 @@ +name: Docker ECR Push - Builder + +on: + push: + branches: [main] + tags: + - v** + workflow_dispatch: + + +permissions: + packages: write + contents: read + id-token: write + +# simplest example of using the rust-base action +jobs: + docker-ecr-push: + uses: init4tech/actions/.github/workflows/ecr-build-and-push.yml@main + with: + rust-binary-name: zenith-builder-example + environment: dev + requires-private-deps: true + secrets: + aws-ecr-repository: ${{ secrets.AWS_ECR_REPOSITORY }} + aws-ecr-deployer-role-arn: ${{ secrets.AWS_ECR_DEPLOYER_ROLE_ARN }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/.github/workflows/transaction-sender-ecr-cd.yml b/.github/workflows/transaction-sender-ecr-cd.yml new file mode 100644 index 0000000..fdd069d --- /dev/null +++ b/.github/workflows/transaction-sender-ecr-cd.yml @@ -0,0 +1,28 @@ +name: Docker ECR Push - Transaction Sender + +on: + push: + branches: [main] + tags: + - v** + workflow_dispatch: + + +permissions: + packages: write + contents: read + id-token: write + +# simplest example of using the rust-base action +jobs: + docker-ecr-push: + uses: init4tech/actions/.github/workflows/ecr-build-and-push.yml@main + with: + rust-binary-name: transaction-sender + environment: dev + requires-private-deps: true + dockerfile-path: transaction-sender.Dockerfile + secrets: + aws-ecr-repository: ${{ secrets.AWS_ECR_REPOSITORY }} + aws-ecr-deployer-role-arn: ${{ secrets.AWS_ECR_DEPLOYER_ROLE_ARN }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/transaction-submitter.Dockerfile b/transaction-submitter.Dockerfile new file mode 100644 index 0000000..59ad0c2 --- /dev/null +++ b/transaction-submitter.Dockerfile @@ -0,0 +1,38 @@ +# syntax=docker/dockerfile:1.7-labs +### STAGE 0: Create base chef image for building +### cargo chef is used to speed up the build process by caching dependencies using docker +FROM --platform=$TARGETPLATFORM lukemathwalker/cargo-chef:latest-rust-latest as chef + +RUN cargo install cargo-chef + +WORKDIR /app + +### Stage 1: cargo chef prepare +### Creates the recipe.json file which is a manifest of Cargo.toml files and +### the relevant Cargo.lock file +FROM chef as planner +COPY --exclude=target . . +RUN cargo chef prepare + +### Stage 2: Build the project +### This stage builds the deps of the project (not the code) using cargo chef cook +### and then it copies the source code and builds the actual crates +### this takes advantage of docker layer caching to the max +FROM chef as builder +COPY --from=planner /app/recipe.json recipe.json +RUN apt-get update && apt-get -y upgrade && apt-get install -y gcc libclang-dev pkg-config libssl-dev +RUN rustup target add x86_64-unknown-linux-gnu +RUN rustup toolchain install stable-x86_64-unknown-linux-gnu + +RUN --mount=type=ssh cargo chef cook --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json --bin transaction-submitter +COPY --exclude=target . . + +RUN --mount=type=ssh cargo build --release --target x86_64-unknown-linux-gnu --bin transaction-submitter + +# Stage 3: Final image for running in the env +FROM --platform=$TARGETPLATFORM debian:bookworm-slim +RUN apt-get update && apt-get -y upgrade && apt-get install -y libssl-dev ca-certificates + +COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/transaction-submitter /usr/local/bin/transaction-submitter + +ENTRYPOINT [ "/usr/local/bin/transaction-submitter" ] \ No newline at end of file