Improvements to github actions (#79)

* Improvements to github actions

* Change username to repo owner username
This commit is contained in:
Juan Calderon-Perez 2023-03-26 17:18:01 -04:00 committed by GitHub
parent 4047fbe0be
commit b3cf97ce40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 38 deletions

7
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

View File

@ -1,53 +1,56 @@
name: Create and publish a Docker image
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
workflow_dispatch:
release:
types: [published]
env:
REGISTRY: ghcr.io
OWNER: ${{ github.repository.owner }}
types: [published, edited]
jobs:
build-and-push-image:
build-and-publish-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./Dockerfile
image: serge
context: .
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
- name: Checkout
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
images: |
ghcr.io/nsarrazin/serge
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: nsarrazin
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ github.event.repository.owner.name }}/${{ matrix.image }}
- name: Build and Publish Docker Image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v4
with:
file: ${{ matrix.dockerfile }}
context: ${{ matrix.context }}
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}:release
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}:${{ github.event.release.tag_name }}
context: .
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}