From ca0ef210d35448b8147b9d822a4eca31cc9f3071 Mon Sep 17 00:00:00 2001 From: AshtonStephens Date: Wed, 23 Oct 2024 19:05:04 +0100 Subject: [PATCH] feat: Test docker container publishing --- .github/actions/dockerfiles/Dockerfile.debian | 45 +++++++++++++++++++ .github/workflows/image-build.yaml | 20 ++++++--- 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 .github/actions/dockerfiles/Dockerfile.debian diff --git a/.github/actions/dockerfiles/Dockerfile.debian b/.github/actions/dockerfiles/Dockerfile.debian new file mode 100644 index 000000000..859f862f5 --- /dev/null +++ b/.github/actions/dockerfiles/Dockerfile.debian @@ -0,0 +1,45 @@ +FROM rust:1.81-slim-bookworm as builder + +# Install dependencies. +RUN apt-get update +RUN apt-get install -y \ + libclang-dev \ + git \ + pkg-config \ + libssl-dev \ + make \ + protobuf-compiler \ + npm \ + default-jre +RUN npm install -g pnpm@9 +RUN npm install -g @openapitools/openapi-generator-cli + +WORKDIR /code/sbtc +COPY . . +RUN make install && make build + +# Create Docker image to run the emily server. +FROM debian:bookworm-slim AS emily-server +WORKDIR /code +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=build /code/sbtc/target/debug/emily-server /usr/local/bin/emily-server +# Server configuration. +ENV HOST=0.0.0.0 +ENV PORT=3030 +# AWS configuration. +ENV AWS_ACCESS_KEY_ID=xxxxxxxxxxxx +ENV AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxx +ENV AWS_REGION=us-west-2 +ENV DYNAMODB_ENDPOINT=http://dynamodb:8000 +ENTRYPOINT ["/bin/sh", "-c", "/usr/local/bin/emily-server --host $HOST --port $PORT --dynamodb-endpoint $DYNAMODB_ENDPOINT"] + +# Create Docker image to run the signer. +FROM debian:bookworm-slim AS signer +COPY --from=build /code/sbtc/target/debug/sbtc-signer /usr/local/bin/sbtc-signer +ENTRYPOINT ["/usr/local/bin/signer --config /signer-config.toml --migrate-db"] + +# Create Docker image to run the blocklist client. +FROM debian:bookworm-slim AS blocklist-client +COPY --from=build /code/sbtc/target/debug/blocklist-client /usr/local/bin/blocklist-client +# TODO(TBD): Fix the blocklist client so it has a configurable config location. +ENTRYPOINT ["/usr/local/bin/blocklist-client"] diff --git a/.github/workflows/image-build.yaml b/.github/workflows/image-build.yaml index 23e75892f..3db9974c4 100644 --- a/.github/workflows/image-build.yaml +++ b/.github/workflows/image-build.yaml @@ -9,10 +9,14 @@ on: required: true type: string description: "Version tag for docker images" + workflow_dispatch: + push: + branches: + - 693-chore-docker-container-publishing ## Define which docker arch to build for env: - docker_platforms: "linux/arm64, linux/arm/v7, linux/amd64, linux/amd64/v3" + docker_platforms: "linux/arm64, linux/arm/v7, linux/amd64, linux/amd64/v3, linux/arm64/v8" docker-org: blockstack concurrency: @@ -37,8 +41,11 @@ jobs: max-parallel: 2 matrix: dist: - - alpine - debian + docker_target: + - signer + - emily-server + - blocklist-client steps: ## Setup Docker for the builds - name: Docker setup @@ -65,9 +72,9 @@ jobs: uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 #v5.5.1 with: ## tag images with current repo name `stacks-core` as well as legacy `stacks-blockchain` + # ${{env.docker-org}}/${{ github.event.repository.name }}/${{ matrix.docker_target }} images: | - ${{env.docker-org}}/${{ github.event.repository.name }} - ${{env.docker-org}}/stacks-blockchain + ${{env.docker-org}}/sbtc/${{ matrix.docker_target }} tags: | type=raw,value=latest,enable=${{ inputs.tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) && matrix.dist == 'debian' }} type=raw,value=${{ inputs.tag }}-${{ matrix.dist }},enable=${{ inputs.tag != '' && matrix.dist == 'debian'}} @@ -77,14 +84,15 @@ jobs: type=raw,value=${{ inputs.tag }}-${{ matrix.dist }},enable=${{ inputs.tag != '' && matrix.dist == 'alpine' }} ## Build docker image for release - - name: Build and Push ( ${{matrix.dist}} ) + - name: Build and Push ( ${{matrix.dist}} ${{matrix.docker_target}} ) id: docker_build uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 with: - file: ./.github/actions/dockerfiles/Dockerfile.${{ matrix.dist }}-binary + file: ./.github/actions/dockerfiles/Dockerfile.${{ matrix.dist }} platforms: ${{ env.docker_platforms }} tags: ${{ steps.docker_metadata.outputs.tags }} labels: ${{ steps.docker_metadata.outputs.labels }} + target: ${{ matrix.docker_target }} build-args: | TAG=${{ inputs.tag }} REPO=${{ github.repository_owner }}/${{ github.event.repository.name }}