From d69d1ca8fe9a79cfa9aabdcc19e81fbadfd70640 Mon Sep 17 00:00:00 2001 From: yp945 Date: Mon, 8 Jul 2024 10:07:50 +0800 Subject: [PATCH] add docker image push ci --- .github/workflows/publish-docker-image.yml | 55 +++++++++++-------- .../images/fiammad/Dockerfile => Dockerfile | 9 --- Makefile | 11 +++- contrib/images/Makefile | 13 ----- scripts/docker/node.docker-compose.yml | 4 +- scripts/docker/validator.docker-compose.yml | 8 +-- 6 files changed, 48 insertions(+), 52 deletions(-) rename contrib/images/fiammad/Dockerfile => Dockerfile (84%) delete mode 100644 contrib/images/Makefile diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index a520aa86..bfa61727 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -1,31 +1,42 @@ -name: Build and Publish Docker Image +# source: https://docs.github.com/en/enterprise-cloud@latest/actions/publishing-packages/publishing-docker-images +name: Create and publish a Docker image + on: push: - branches: - - main - tags: - - "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10 - - "v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5 + branches: ['main'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: - setup-build-publish: - name: Setup, Build and Publish + build-and-push-image: runs-on: ubuntu-latest - environment: production + permissions: + contents: read + packages: write steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3.2.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and Push Docker Image - uses: docker/build-push-action@v2 - with: - file: ./contrib/images/fiammad/Dockerfile - push: true - tags: fiammachain/fiammad:${{ github.ref == 'refs/tags/*' && github.ref || github.sha }} \ No newline at end of file + - name: Build and push Docker image + uses: docker/build-push-action@v6.1.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/contrib/images/fiammad/Dockerfile b/Dockerfile similarity index 84% rename from contrib/images/fiammad/Dockerfile rename to Dockerfile index 82da1144..dae4986b 100644 --- a/contrib/images/fiammad/Dockerfile +++ b/Dockerfile @@ -4,10 +4,7 @@ FROM golang:1.22 AS build-env # TARGETPLATFORM should be one of linux/amd64 or linux/arm64. ARG TARGETPLATFORM="linux/amd64" -# Version to build. Default is empty -ARG VERSION -ARG LEDGER_ENABLED="false" # Cosmos build options ARG COSMOS_BUILD_OPTIONS="" @@ -29,10 +26,6 @@ COPY go.mod go.sum . RUN go mod download # Then copy everything else COPY . . -# If version is set, then checkout this version -RUN if [ -n "${VERSION}" ]; then \ - git checkout -f ${VERSION}; \ - fi RUN LEDGER_ENABLED=$LEDGER_ENABLED \ BUILD_TAGS=$BUILD_TAGS \ @@ -44,8 +37,6 @@ FROM debian:bookworm-slim AS run RUN apt-get update && apt-get install -y bash curl jq wget pkg-config openssl libssl-dev -# Label should match your github repo -LABEL org.opencontainers.image.source="https://github.com/fiamma-chain/fiammad:${VERSION}" # Install libraries # Cosmwasm - Download correct libwasmvm version diff --git a/Makefile b/Makefile index 3b19d6c0..dc2a4bc6 100644 --- a/Makefile +++ b/Makefile @@ -219,6 +219,13 @@ test: ############################################################################### build-docker: - $(MAKE) -C contrib/images fiammad + docker build \ + -t fiammachain/fiammad \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + -f Dockerfile . -.PHONY: build-docker \ No newline at end of file +docker-rmi: + docker rmi fiammachain/fiammad 2>/dev/null; true + +.PHONY: build-docker docker-rmi \ No newline at end of file diff --git a/contrib/images/Makefile b/contrib/images/Makefile deleted file mode 100644 index c8dccdc8..00000000 --- a/contrib/images/Makefile +++ /dev/null @@ -1,13 +0,0 @@ - - -all: fiammad - -fiammad: fiammad-rmi - docker build --tag fiammachain/fiammad -f fiammad/Dockerfile \ - $(shell git rev-parse --show-toplevel) - -fiammad-rmi: - docker rmi fiammachain/fiammad 2>/dev/null; true - - -.PHONY: all fiammad fiammad-rmi diff --git a/scripts/docker/node.docker-compose.yml b/scripts/docker/node.docker-compose.yml index 3e42fa79..2beac393 100644 --- a/scripts/docker/node.docker-compose.yml +++ b/scripts/docker/node.docker-compose.yml @@ -5,7 +5,7 @@ services: image: fiammachain/fiammad build: context: ../../ - dockerfile: ../../contrib/images/fiammad/Dockerfile + dockerfile: ../../Dockerfile volumes: - ../testnet-nodes/${NODE_NAME}:/root/.fiamma - ../setup_node.sh:/entrypoint.sh @@ -14,7 +14,7 @@ services: node-runner: image: fiammachain/fiammad build: - dockerfile: ../../contrib/images/fiammad/Dockerfile + dockerfile: ../../Dockerfile volumes: - ../testnet-nodes/${NODE_NAME}:/root/.fiamma command: start diff --git a/scripts/docker/validator.docker-compose.yml b/scripts/docker/validator.docker-compose.yml index ef513f33..82af6bd8 100644 --- a/scripts/docker/validator.docker-compose.yml +++ b/scripts/docker/validator.docker-compose.yml @@ -5,7 +5,7 @@ services: image: fiammachain/fiammad build: context: ../../ - dockerfile: ./contrib/images/fiammad/Dockerfile + dockerfile: ../../Dockerfile volumes: - ../testnet-nodes/${NODE_NAME}:/root/.fiamma - ../setup_node.sh:/entrypoint.sh @@ -14,8 +14,8 @@ services: validator-setup: image: fiammachain/fiammad build: - context: ../ - dockerfile: ./contrib/images/fiammad/Dockerfile + context: ../../ + dockerfile: ../../Dockerfile volumes: - ../testnet-nodes/${NODE_NAME}:/root/.fiamma - ../setup_validator.sh:/entrypoint.sh @@ -25,7 +25,7 @@ services: image: fiammachain/fiammad build: context: ../../ - dockerfile: ./contrib/images/fiammad/Dockerfile + dockerfile: ../../Dockerfile ports: - 26656:26656 - 26657:26657