Skip to content

Build Image and Push #41

Build Image and Push

Build Image and Push #41

name: Build Image and Push
on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: '0 0 * * SUN'
# Sets permissions of the GITHUB_TOKEN
permissions:
packages: write
contents: read
env:
GHCR_REPO: ghcr.io/${{ github.repository_owner }}/stunnel
DOCKERHUB_REPO: bonztm/stunnel
jobs:
build-push-stunnel:
runs-on:
- stunnel
steps:
- name: checkout repo content
uses: actions/checkout@v4
- name: Get current date
id: date
run: echo "date=$(date --rfc-3339=date)" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create docker context
run: |
docker context create stunnel
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
endpoint: stunnel
- name: Generate docker image tags
id: metadata
uses: docker/metadata-action@v5
with:
flavor: |
latest=true
images: |
${{ env.GHCR_REPO }}
${{ env.DOCKERHUB_REPO }}
tags: |
type=ref,event=pr
type=ref,event=branch
type=raw,value=${{ steps.date.outputs.date }}
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.metadata.outputs.tags }}
- name: Remove docker context
if: always()
run: docker context rm stunnel
- name: Update Dockerhub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.DOCKERHUB_REPO }}
readme-filepath: README.md
short-description: ${{ github.event.repository.description }}