-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add Docker Hub and GitHub Container Registry image publishing …
…workflow
- Loading branch information
sofia-assis
committed
May 10, 2024
1 parent
2251314
commit d48ed4a
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.github/workflows/publish-website-monitor-docker-image.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Template for Docker Image Push to Docker Hub | ||
on: | ||
push: | ||
branches: [ "main", "dev"] | ||
workflow_dispatch: # allow user to specify which | ||
inputs: | ||
environment: | ||
description: 'Target environment' | ||
required: true | ||
default: 'dev' # default value if not provided | ||
|
||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker Image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v4 | ||
- name: Build version | ||
id: date | ||
run: echo "{name}=date::$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: | | ||
ninjaasa/template-python-project | ||
ghcr.io/${{ github.repository }} | ||
# tag image to be latest if pushing to main branch, dev if pushing to dev branch | ||
tags: | | ||
type=raw,value=${{github.run_id}} | ||
type=raw,value=${{ github.ref == 'refs/heads/main' && 'latest' || 'dev' }} | ||
labels: | | ||
org.label-schema.build-date=${{ steps.date.outputs.date}} | ||
org.opencontainers.image.created=${{ steps.date.outputs.date}} | ||
- name: Build and push Docker image | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from placeholder import placeholder | ||
|
||
def main(): | ||
print(placeholder()) | ||
|
||
if __name__ == '__main__': | ||
main() |