-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (54 loc) · 1.92 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Docker
on:
push:
branches:
- main
pull_request:
release:
types: [published]
workflow_dispatch:
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true
jobs:
docker:
permissions:
packages: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
## Login to Docker Hub and/or GitHub container registry
- name: Login to GitHub container registry
if: ${{ github.event_name == 'release' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
if: ${{ github.event_name == 'release' && env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_PASSWORD != '' }}
id: login-dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
## Extract metadata (tags, labels) from Git reference and GitHub events for the Docker image
- name: Extract metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ github.repository }},enable=true
name=${{ github.repository }},enable=${{ steps.login-dockerhub.outcome == 'success' }}
## Build and push if the workflow was triggered by a release
- name: Build (and push on release)
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}