From 9cfdd218366c587600adf8579c5e8d8f292204b7 Mon Sep 17 00:00:00 2001 From: Daniele Lisi <22307776+danielelisi@users.noreply.github.com> Date: Tue, 3 Oct 2023 23:58:18 +0200 Subject: [PATCH] Add Github Workflow to build and push a docker image to GHCR --- .github/workflows/docker.yml | 58 ++++++++++++++++++++++++++++++++++++ .gitignore | 5 +++- Dockerfile | 21 +++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..da5019d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,58 @@ +--- + name: Build and Publish Docker image + + on: + push: + tags: + - "v*" + branches: + - '*' + pull_request: + branches: + - 'main' + + jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/ecadlabs/go-tezos-keygen + tags: | + type=ref,event=branch,suffix=-{{sha}} + type=ref,event=pr,suffix=-{{sha}} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + \ No newline at end of file diff --git a/.gitignore b/.gitignore index f260c8f..398b63c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ # Go workspace file go.work -/go-tezos-keygen \ No newline at end of file +/go-tezos-keygen +*.db +networks.yaml +.vscode diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..01aeda2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.21-bullseye AS builder + +WORKDIR /src + +# Caching step +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN go build -o /go-tezos-keygen + +FROM debian:bullseye-slim as runtime + +WORKDIR /app + +COPY --from=builder /go-tezos-keygen /app/go-tezos-keygen + +EXPOSE 3000 + +ENTRYPOINT ["/app/go-tezos-keygen"]