Build, Push Container image to DockerHub #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Push Container image to DockerHub | |
on: | |
workflow_dispatch: | |
# schedule: | |
# - cron: '0 0 * * 6' # At 12:00 AM, only on Saturday | |
env: | |
IMAGE_NAME: "clamav-rest" | |
REGISTRY_USER: ajilaag | |
REGISTRY_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
image_digest: ${{ steps.container_metadata.outputs.digest }} | |
image_tags: ${{ steps.meta_dev.outputs.tags }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Log in to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ env.REGISTRY_USER }} | |
password: ${{ env.REGISTRY_PASSWORD }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta_dev | |
uses: docker/metadata-action@v4 | |
with: | |
images: ajilaag/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value={{date 'YYYYMMDD'}} | |
Type=raw,value=latest,enable={{is_default_branch}} | |
- name: Build and push to DockerHub | |
id: container_metadata | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta_dev.outputs.tags }} | |
labels: ${{ steps.meta_dev.outputs.labels }} | |
- name: Get current date | |
id: date | |
run: echo "::set-output name=date::$(date +'%Y%m%d')" | |
- name: Add version tag | |
id: tag_version | |
uses: laputansoft/github-tag-action@v4.6 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ steps.date.outputs.date }} | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ steps.date.outputs.date }} | |
name: Release ${{ steps.date.outputs.date }} | |
body: ${{ steps.tag_version.outputs.changelog }} |