Skip to content

Commit

Permalink
fix: Add versioning to GHCR and DockerHub images
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf committed May 31, 2023
1 parent 18efe55 commit 405e1ad
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/publish-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
name: Build and Publish Docker Image to DockerHub
name: Publish Image to DockerHub

on:
push:
branches: ["main"]

workflow_dispatch:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: DockerHub Login
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Read YAML file for version
uses: pietrobolcato/action-read-yaml@1.0.0
id: read_yaml
with:
config: ${{ github.workspace }}/version.yaml

- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ secrets.DOCKERHUB_USERNAME }}/devops
run: docker build . --file Dockerfile --tag ${{ secrets.DOCKERHUB_USERNAME }}/devops:${{ steps.read_yaml.outputs['version'] }}

- name: Docker Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/devops
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/devops:${{ steps.read_yaml.outputs['version'] }}
22 changes: 15 additions & 7 deletions .github/workflows/publish-ghcr.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Create and publish a Docker image to GitHub Container Registry
name: Publish Package - GHCR

on:
push:
branches: ['main']
release:
types: [published]

env:
REGISTRY: ghcr.io
Expand All @@ -20,22 +20,30 @@ jobs:
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Read YAML file for version
uses: pietrobolcato/action-read-yaml@1.0.0
id: read_yaml
with:
config: ${{ github.workspace }}/version.yaml

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ghcr.io/pradumnasaraf/devops:latest
tags: |
ghcr.io/pradumnasaraf/devops:latest
ghcr.io/pradumnasaraf/devops:${{ steps.read_yaml.outputs['version'] }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: TriPSs/conventional-changelog-action@v3.7.1
with:
github-token: ${{ secrets.PA_TOKEN }}
version-file: './releases.json'
version-file: './version.yaml'

- name: create release
uses: actions/create-release@v1
Expand Down
3 changes: 0 additions & 3 deletions releases.json

This file was deleted.

1 change: 1 addition & 0 deletions releases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 1.3.2

0 comments on commit 405e1ad

Please sign in to comment.