From efb4ebde490eb0bd631cd7aa11d805813d06dba8 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Thu, 21 Nov 2024 15:13:50 +0400 Subject: [PATCH] ci: Add workflow to build (private) docker images (#399) * ci: Add workflow to build (private) docker images * Add dockerfile * Only build on merge --- .github/workflows/build-push-docker.yml | 62 +++++++++++++++++++++++++ Dockerfile | 36 ++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/build-push-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml new file mode 100644 index 00000000..928b7a2b --- /dev/null +++ b/.github/workflows/build-push-docker.yml @@ -0,0 +1,62 @@ +name: Build and push Docker image +on: + push: + branches: + - main + tags: + - "*" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build-push-image: + name: Build and push Docker image + runs-on: [matterlabs-ci-runner] + steps: + - uses: actions/checkout@v4 + + - name: Set git SHA + id: git_sha + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Set Docker tag + id: docker_tag + run: | + ts=$(date +%s%N | cut -b1-13) + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then + echo "tag=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then + echo "tag=none" >> $GITHUB_OUTPUT + else + echo "Unsupported event ${GITHUB_EVENT_NAME} or ref ${GITHUB_REF}, only refs/heads/, refs/tags/ and pull_request are supported." + exit 1 + fi + + - name: Login to GAR + run: | + gcloud auth configure-docker us-docker.pkg.dev -q + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # For now, we're only pushing to the internal registry + - name: Build and push Docker image + id: docker_build + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }} + tags: | + us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/era-test-node:${{ steps.docker_tag.outputs.tag }} + us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/era-test-node:latest + + - name: Print image digest to summary + run: | + echo "Image tag: ${{ steps.docker_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6a2a3e44 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM ubuntu:22.04 AS builder + +ENV DEBIAN_FRONTEND=noninteractive +ENV DEBCONF_NONINTERACTIVE_SEEN=true + +RUN apt-get update && apt-get install -y curl clang openssl libssl-dev gcc g++ \ + pkg-config build-essential libclang-dev linux-libc-dev liburing-dev && \ + rm -rf /var/lib/apt/lists/* + +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH + +RUN curl https://sh.rustup.rs -sSf | bash -s -- -y && \ + rustup install nightly-2024-08-01 && \ + rustup default nightly-2024-08-01 + +WORKDIR /usr/src/era-test-node +COPY . . + +RUN cargo build --release + +FROM ubuntu:22.04 + +RUN apt-get update && \ + apt-get install -y \ + ca-certificates \ + && \ + rm -rf /var/lib/apt/lists/* + +EXPOSE 8011 + +WORKDIR /usr/local/bin +COPY --from=builder /usr/src/era-test-node/target/release/era_test_node . + +ENTRYPOINT [ "era_test_node" ]