Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve docker push workflow #4465

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,36 @@ on:
push:
branches:
- 3.x
# Build and push Docker images *only* for releases.
release:
types: [published] # , created, edited
types: [published]

jobs:
push_to_registry:
name: Build and push Docker image to Docker Hub
runs-on: ubuntu-22.04

steps:
- name: Check out the repo with latest code
- name: Check out the repo with the latest code
uses: actions/checkout@v4
- name: Push latest to Docker Hub
uses: docker/build-push-action@v6 # Info: https://github.com/docker/build-push-action/tree/releases/v1#tags

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ secrets.DOCKERHUB_REPOSITORY }}
tag_with_ref: true # Info: https://github.com/docker/build-push-action/tree/releases/v1#tag_with_ref
tag_with_sha: true # Info: https://github.com/docker/build-push-action/tree/releases/v1#tag_with_sha
tags: latest

- name: 'Get the current tag'
- name: Get the current tag
id: currentTag
uses: actions/checkout@v4
- run: git fetch --prune --unshallow && TAG=$(git describe --tags --abbrev=0) && echo $TAG && echo "TAG="$TAG >> "$GITHUB_ENV"
- name: Check out the repo with tag
uses: actions/checkout@v4
with:
ref: ${{ env.TAG }}
run: echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

- name: Push current tag to Docker Hub
uses: docker/build-push-action@v6 # Info: https://github.com/docker/build-push-action/tree/releases/v1#tags
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ secrets.DOCKERHUB_REPOSITORY }}
tag_with_ref: true # Info: https://github.com/docker/build-push-action/tree/releases/v1#tag_with_ref
tag_with_sha: true # Info: https://github.com/docker/build-push-action/tree/releases/v1#tag_with_sha
tags: ${{ env.TAG }}
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_REPOSITORY }}:latest
${{ secrets.DOCKERHUB_REPOSITORY }}:${{ env.TAG }}
Loading