From be9897c5738451b10f7a52f0bb9826e312f001e1 Mon Sep 17 00:00:00 2001 From: Cristian Bajenaru Date: Mon, 1 Jul 2024 17:07:47 +0300 Subject: [PATCH 1/2] Add Git workflow for Docker publish --- .github/actions/docker-publish/action.yaml | 83 ++++++++++++++++++++++ .github/workflows/docker-publish.yaml | 34 +++++++++ 2 files changed, 117 insertions(+) create mode 100644 .github/actions/docker-publish/action.yaml create mode 100644 .github/workflows/docker-publish.yaml diff --git a/.github/actions/docker-publish/action.yaml b/.github/actions/docker-publish/action.yaml new file mode 100644 index 00000000..d788a60c --- /dev/null +++ b/.github/actions/docker-publish/action.yaml @@ -0,0 +1,83 @@ +name: 'Build & Push Docker' + +inputs: + compose-version: + description: 'Docker Dompose version' + default: 2.6.0 + registry: + description: 'Docker registry service' + default: ghcr.io + username: + description: 'Username for https://ghcr.io' + required: true + password: + description: 'Password for https://ghcr.io' + required: true + image: + description: 'Image name with provider url' + required: true + dockerfile: + description: 'Path to the Dockerfile' + required: true + context: + description: 'Path to the Context' + default: . + required: true + build-args: + description: 'List of build-time variables' + required: false + +outputs: + image: + description: 'Image url' + value: ${{ steps.imageOuput.outputs.imageUrl }} + imageid: + description: 'Image ID' + value: ${{ steps.publish.outputs.imageId }} + digest: + description: 'Image digest' + value: ${{ steps.publish.outputs.digest }} + metadata: + description: 'Build result metadata' + value: ${{ steps.publish.outputs.metadata }} + +runs: + using: 'composite' + steps: + - name: Log in to the ghcr.io registry + uses: docker/login-action@v2 + with: + registry: ${{ inputs.registry }} + username: ${{ inputs.username }} + password: ${{ inputs.password }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ${{ inputs.image }} + tags: | + type=ref,event=branch + type=sha,prefix= + type=semver,pattern={{raw}} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push the image to ghcr.io + uses: docker/build-push-action@v4 + id: publish + with: + context: ${{ inputs.context }} + file: ${{ inputs.dockerfile }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: ${{ inputs.build-args }} + cache-from: type=gha + cache-to: type=gha,mode=max + - id: imageOuput + shell: bash + run: | + echo "imageUrl=${{ fromJSON(steps.publish.outputs.metadata)['image.name'] }}" >> $GITHUB_OUTPUT diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml new file mode 100644 index 00000000..e84d51a3 --- /dev/null +++ b/.github/workflows/docker-publish.yaml @@ -0,0 +1,34 @@ +name: Build and publish Docker image + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize] + release: + types: [published] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build-and-publish-image: + runs-on: buildjet-4vcpu-ubuntu-2204 + if: | + (github.event_name == 'release' && github.event.action == 'published') || + github.ref == 'refs/heads/main' || + (github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository) + steps: + - uses: actions/checkout@v3 + + - name: Build and push Fuel Explorer Graphql image + uses: ./.github/actions/docker-publish + id: publish + with: + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + image: ghcr.io/fuellabs/data-systems + dockerfile: docker/fuel-core-nats.Dockerfile From 4b2eb548a031b556cee9ef8ee501fc42b18c2a0a Mon Sep 17 00:00:00 2001 From: Cristian Bajenaru Date: Mon, 1 Jul 2024 18:19:24 +0300 Subject: [PATCH 2/2] Update image name --- .github/workflows/docker-publish.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml index e84d51a3..896dd9f2 100644 --- a/.github/workflows/docker-publish.yaml +++ b/.github/workflows/docker-publish.yaml @@ -24,11 +24,11 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Build and push Fuel Explorer Graphql image + - name: Build and push Fuel Core NATS image uses: ./.github/actions/docker-publish id: publish with: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - image: ghcr.io/fuellabs/data-systems + image: ghcr.io/fuellabs/fuel-core-nats dockerfile: docker/fuel-core-nats.Dockerfile