-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 \ | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |