From 7ab955a9d717ec571f49fc3c59d5b376d6b3bf68 Mon Sep 17 00:00:00 2001 From: Techwoo Date: Thu, 7 Nov 2024 17:54:51 -0800 Subject: [PATCH] feat(docker): add dockerfile and workflow (#348) Dear team, I have created dockerfile and worflow to make story image. The REPOSITORY_URI environment and GITHUB_TOKEN secret needed to be set up to run the workflow. issue: none --------- Co-authored-by: Andy Wu --- .github/workflows/ci-docker-hub.yml | 60 +++++++++++++++++++++++++++++ Dockerfile | 37 ++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 .github/workflows/ci-docker-hub.yml create mode 100644 Dockerfile diff --git a/.github/workflows/ci-docker-hub.yml b/.github/workflows/ci-docker-hub.yml new file mode 100644 index 00000000..6cc2cee9 --- /dev/null +++ b/.github/workflows/ci-docker-hub.yml @@ -0,0 +1,60 @@ +name: Build and Push to Docker Hub + +on: + workflow_dispatch: + push: + tags: + - '*' + +jobs: + # Build and upload the geth binary + build_and_push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 + + - name: Set build arguments + run: | + echo "REPOSITORY_URI=${{ vars.REPOSITORY_URI }}" >> $GITHUB_ENV + echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV + echo "BUILDNUM=${{ github.run_number }}" >> $GITHUB_ENV + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Dockerize the geth and bootnode binary + env: + DOCKER_BUILDKIT: 1 + run: | + docker buildx create --use + docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm64/v8 \ + --build-arg BUILDNUM=$BUILDNUM \ + --build-arg COMMIT=$COMMIT \ + --build-arg VERSION=$VERSION \ + -t $REPOSITORY_URI:latest \ + -t $REPOSITORY_URI:$COMMIT \ + -t $REPOSITORY_URI:$VERSION \ + --cache-from=type=local,src=/tmp/.buildx-cache \ + --cache-to=type=local,dest=/tmp/.buildx-cache \ + --push \ + -f ./Dockerfile \ + . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8a01fe12 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# Support setting various labels on the final image +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +# Build Geth in a stock Go builder container +FROM golang:1.22-alpine as builder + +# Set the Current Working Directory inside the container +WORKDIR /story + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download all dependencies. Dependencies are cached if the go.mod and go.sum files are not changed +RUN go mod download + +ADD . /story/ +RUN go build -o story ./client + +# Pull Geth into a second stage deploy alpine container +FROM alpine:latest + +RUN apk add --no-cache ca-certificates +COPY --from=builder /story/story /usr/local/bin/ + +EXPOSE 1317 26656 26657 26660 + +WORKDIR /root/.story/story +ENTRYPOINT ["/bin/sh", "-c", "story init --network $NETWORK && exec story run \"$@\"", "--"] + +# Add some metadata labels to help programmatic image consumption +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" network="$NETWORK"