Commit 5d628aff authored by tom goriunov's avatar tom goriunov Committed by GitHub

reusable workflow for publishing docker image (#1218)

* [skip ci] reusable workflow for publishing docker image

* [skip ci] clean up

* [skip ci] fix image name
parent b2b1c377
...@@ -12,43 +12,8 @@ concurrency: ...@@ -12,43 +12,8 @@ concurrency:
jobs: jobs:
publish_image: publish_image:
name: Publish Docker image name: Publish Docker image
runs-on: ubuntu-latest uses: './.github/workflows/publish-image.yml'
steps: secrets: inherit
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Will automatically make nice tags, see the table here https://github.com/docker/metadata-action#basic
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/blockscout/frontend
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_SHA=${{ env.SHORT_SHA }}
deploy_main: deploy_main:
name: Deploy frontend name: Deploy frontend
......
...@@ -4,61 +4,33 @@ on: ...@@ -4,61 +4,33 @@ on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
publish_image: make_slug:
name: Publish Docker image name: Make GitHub reference slug
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
shortSha: ${{ steps.output-step.outputs.short-sha }} REF_SLUG: ${{ steps.output.outputs.REF_SLUG }}
steps: steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Inject slug/short variables - name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.4.1 uses: rlespinasse/github-slug-action@v4.4.1
- name: Set up Docker Buildx - name: Set output
uses: docker/setup-buildx-action@v2 id: output
run: echo "REF_SLUG=${{ env.GITHUB_REF_NAME_SLUG }}" >> $GITHUB_OUTPUT
# Will automatically make nice tags, see the table here https://github.com/docker/metadata-action#basic
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/blockscout/frontend
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Add outputs
run: |
echo "::set-output name=short-sha::${{ env.SHORT_SHA }}"
id: output-step
- name: Build and push publish_image:
uses: docker/build-push-action@v3 name: Publish Docker image
needs: make_slug
uses: './.github/workflows/publish-image.yml'
with: with:
context: . tags: ghcr.io/blockscout/frontend:review-${{ needs.make_slug.outputs.REF_SLUG }}
file: ./Dockerfile secrets: inherit
push: true
cache-from: type=gha
tags: ghcr.io/blockscout/frontend:prerelease-${{ env.GITHUB_REF_NAME_SLUG }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_SHA=${{ env.SHORT_SHA }}
deploy_review_l2: deploy_review_l2:
name: Deploy frontend (L2) name: Deploy frontend (L2)
needs: publish_image needs: [ make_slug, publish_image ]
uses: blockscout/blockscout-ci-cd/.github/workflows/deploy_helmfile.yaml@master uses: blockscout/blockscout-ci-cd/.github/workflows/deploy_helmfile.yaml@master
with: with:
appName: review-l2-$GITHUB_REF_NAME_SLUG appName: review-l2-${{ needs.make_slug.outputs.REF_SLUG }}
globalEnv: review globalEnv: review
helmfileDir: deploy helmfileDir: deploy
kubeConfigSecret: ci/data/dev/kubeconfig/k8s-dev kubeConfigSecret: ci/data/dev/kubeconfig/k8s-dev
......
...@@ -4,61 +4,33 @@ on: ...@@ -4,61 +4,33 @@ on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
publish_image: make_slug:
name: Publish Docker image name: Make GitHub reference slug
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
shortSha: ${{ steps.output-step.outputs.short-sha }} REF_SLUG: ${{ steps.output.outputs.REF_SLUG }}
steps: steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Inject slug/short variables - name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.4.1 uses: rlespinasse/github-slug-action@v4.4.1
- name: Set up Docker Buildx - name: Set output
uses: docker/setup-buildx-action@v2 id: output
run: echo "REF_SLUG=${{ env.GITHUB_REF_NAME_SLUG }}" >> $GITHUB_OUTPUT
# Will automatically make nice tags, see the table here https://github.com/docker/metadata-action#basic
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/blockscout/frontend
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Add outputs
run: |
echo "::set-output name=short-sha::${{ env.SHORT_SHA }}"
id: output-step
- name: Build and push publish_image:
uses: docker/build-push-action@v3 name: Publish Docker image
needs: make_slug
uses: './.github/workflows/publish-image.yml'
with: with:
context: . tags: ghcr.io/blockscout/frontend:review-${{ needs.make_slug.outputs.REF_SLUG }}
file: ./Dockerfile secrets: inherit
push: true
cache-from: type=gha
tags: ghcr.io/blockscout/frontend:prerelease-${{ env.GITHUB_REF_NAME_SLUG }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_SHA=${{ env.SHORT_SHA }}
deploy_review: deploy_review:
name: Deploy frontend name: Deploy frontend
needs: publish_image needs: [ make_slug, publish_image ]
uses: blockscout/blockscout-ci-cd/.github/workflows/deploy_helmfile.yaml@master uses: blockscout/blockscout-ci-cd/.github/workflows/deploy_helmfile.yaml@master
with: with:
appName: review-$GITHUB_REF_NAME_SLUG appName: review-${{ needs.make_slug.outputs.REF_SLUG }}
globalEnv: review globalEnv: review
helmfileDir: deploy helmfileDir: deploy
kubeConfigSecret: ci/data/dev/kubeconfig/k8s-dev kubeConfigSecret: ci/data/dev/kubeconfig/k8s-dev
......
...@@ -11,54 +11,8 @@ concurrency: ...@@ -11,54 +11,8 @@ concurrency:
jobs: jobs:
publish_image: publish_image:
name: Publish Docker image name: Publish Docker image
runs-on: ubuntu-latest uses: './.github/workflows/publish-image.yml'
outputs: secrets: inherit
shortSha: ${{ steps.output-step.outputs.short-sha }}
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.4.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Will automatically make nice tags, see the table here https://github.com/docker/metadata-action#basic
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/blockscout/frontend
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Add outputs
run: |
echo "::set-output name=short-sha::${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
id: output-step
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
cache-from: type=gha
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_SHA=${{ env.SHORT_SHA }}
GIT_TAG=${{ github.ref_type == 'tag' && github.ref_name || '' }}
deploy_e2e: deploy_e2e:
name: Deploy E2E instance name: Deploy E2E instance
...@@ -83,7 +37,7 @@ jobs: ...@@ -83,7 +37,7 @@ jobs:
with: with:
owner: blockscout owner: blockscout
repo: deployment-values repo: deployment-values
github_token: ${{env.WORKFLOW_TRIGGER_TOKEN}} github_token: ${{ env.WORKFLOW_TRIGGER_TOKEN }}
workflow_file_name: deploy_blockscout.yaml workflow_file_name: deploy_blockscout.yaml
ref: main ref: main
wait_interval: 30 wait_interval: 30
......
...@@ -4,7 +4,7 @@ on: ...@@ -4,7 +4,7 @@ on:
workflow_dispatch: workflow_dispatch:
push: push:
tags: tags:
- 'v[0-9]+.[0-9]+.[0-9]+-[a-z]+' # e.g v1.2.3-alpha - 'v[0-9]+.[0-9]+.[0-9]+-[a-z]+*' # e.g v1.2.3-alpha
jobs: jobs:
checks: checks:
...@@ -24,4 +24,5 @@ jobs: ...@@ -24,4 +24,5 @@ jobs:
with: with:
tag: ${{ github.ref_name }} tag: ${{ github.ref_name }}
label_name: 'pre-release' label_name: 'pre-release'
label_description: Tasks in pre-release right now
secrets: inherit secrets: inherit
name: Publish Docker image
on:
workflow_dispatch:
inputs:
tags:
description: Image tags
required: false
type: string
workflow_call:
inputs:
tags:
description: Image tags
required: false
type: string
jobs:
run:
name: Run
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Will automatically make nice tags, see the table here https://github.com/docker/metadata-action#basic
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/blockscout/frontend
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Debug
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
run: |
echo "ref_type: $REF_TYPE"
echo "ref_name: $REF_NAME"
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
cache-from: type=gha
tags: ${{ inputs.tags || steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_SHA=${{ env.SHORT_SHA }}
GIT_TAG=${{ github.ref_type == 'tag' && github.ref_name || '' }}
\ No newline at end of file
...@@ -69,62 +69,7 @@ jobs: ...@@ -69,62 +69,7 @@ jobs:
issues: ${{ needs.label_released_issues.outputs.issues }} issues: ${{ needs.label_released_issues.outputs.issues }}
secrets: inherit secrets: inherit
# TODO @tom2drum refactor to reusable workflow
publish_image: publish_image:
name: Publish Docker image name: Publish Docker image
runs-on: ubuntu-latest uses: './.github/workflows/publish-image.yml'
outputs: secrets: inherit
shortSha: ${{ steps.output-step.outputs.short-sha }}
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.4.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Will automatically make nice tags, see the table here https://github.com/docker/metadata-action#basic
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/blockscout/frontend
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Debug
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
run: |
echo "ref_type: $REF_TYPE"
echo "ref_name: $REF_NAME"
- name: Add outputs
run: |
echo "::set-output name=short-sha::${{ env.GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT }}"
id: output-step
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
cache-from: type=gha
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_COMMIT_SHA=${{ env.SHORT_SHA }}
GIT_TAG=${{ github.ref_type == 'tag' && github.ref_name || '' }}
...@@ -4,7 +4,7 @@ frontend: ...@@ -4,7 +4,7 @@ frontend:
app: blockscout app: blockscout
enabled: true enabled: true
image: image:
_default: ghcr.io/blockscout/frontend:prerelease-{{ requiredEnv "GITHUB_REF_NAME_SLUG" }} _default: ghcr.io/blockscout/frontend:review-{{ requiredEnv "GITHUB_REF_NAME_SLUG" }}
pullPolicy: Always pullPolicy: Always
ingress: ingress:
enabled: true enabled: true
......
...@@ -4,7 +4,7 @@ frontend: ...@@ -4,7 +4,7 @@ frontend:
app: blockscout app: blockscout
enabled: true enabled: true
image: image:
_default: ghcr.io/blockscout/frontend:prerelease-{{ requiredEnv "GITHUB_REF_NAME_SLUG" }} _default: ghcr.io/blockscout/frontend:review-{{ requiredEnv "GITHUB_REF_NAME_SLUG" }}
pullPolicy: Always pullPolicy: Always
ingress: ingress:
enabled: true enabled: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment