-
Notifications
You must be signed in to change notification settings - Fork 2
91 lines (84 loc) · 2.95 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Docker
on:
push:
branches:
- main
paths-ignore:
- "docs/**"
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
if: ${{ github.actor != 'dependabot[bot]' }}
strategy:
fail-fast: false
matrix:
dockerfile:
- Dockerfile
steps:
## Free up space by removing unnecessary files
- name: Maximize build space
uses: AdityaGarg8/remove-unwanted-software@v4
with:
remove-android: "true"
remove-cached-tools: "true"
remove-codeql: "true"
remove-docker-images: "true"
remove-dotnet: "true"
remove-haskell: "true"
remove-large-packages: "true"
- 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 }}
- name: Login to NGC
env:
NVCR_USERNAME: ${{ secrets.NVCR_USERNAME }}
NVCR_PASSWORD: ${{ secrets.NVCR_PASSWORD }}
if: ${{ env.NVCR_USERNAME != '' && env.NVCR_PASSWORD != '' }}
uses: docker/login-action@v3
with:
registry: nvcr.io
username: ${{ secrets.NVCR_USERNAME }}
password: ${{ secrets.NVCR_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@v6
with:
context: .
file: ${{ matrix.dockerfile }}
push: ${{ github.event_name == 'release' && matrix.dockerfile == 'Dockerfile' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}