Skip to content

Commit

Permalink
build and push image to ghcr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
martini-source committed Jul 1, 2024
1 parent 8fea2ac commit 633c6e8
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,47 @@ name: Build & Push Container Image
on:
push:
branches:
- main
- master
tags:
- v*
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
# Push image to GitHub Packages.
container:
runs-on: ubuntu-latest
env:
IMAGE: docker.io/vshn/modsecurity
QUAY_IMAGE: quay.io/vshn/modsecurity
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Set version latest
if: github.ref == 'refs/heads/master'
run: echo "VERSION=latest" >> ${GITHUB_ENV}
- name: Set version from tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/})" >> ${GITHUB_ENV}
- name: Build Image
run: docker build -t "${IMAGE}:${VERSION}" v3.3
- name: Push Image to DockerHub
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
docker login docker.io --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}"
docker push "${IMAGE}:${VERSION}"
- name: Push Image to Quay
env:
DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.QUAY_PASSWORD }}
run: |
docker login quay.io --username "${DOCKER_USERNAME}" --password "${DOCKER_PASSWORD}"
docker tag "${IMAGE}:${VERSION}" ${QUAY_IMAGE}:${VERSION}
docker push "${QUAY_IMAGE}:${VERSION}"
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Log in to the Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Determine Tags & Labels based on Git ref
id: meta
uses: docker/metadata-action@v5
with:
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"

- name: Build & Push container image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
addLatest: true

0 comments on commit 633c6e8

Please sign in to comment.