-
Notifications
You must be signed in to change notification settings - Fork 487
177 lines (166 loc) · 6.2 KB
/
docker.yml
File metadata and controls
177 lines (166 loc) · 6.2 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# adapted from https://raw.githubusercontent.com/stefanprodan/podinfo/master/.github/workflows/release.yml
name: Docker
on:
push:
paths-ignore:
- 'doc/**'
branches-ignore: ["dependabot/**"]
pull_request:
paths-ignore:
- 'doc/**'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build_individual_images:
strategy:
fail-fast: true
matrix:
runners: [ubuntu-24.04, ubuntu-24.04-arm]
runs-on: ${{ matrix.runners }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
env:
PUSH_PACKAGES: ${{ github.repository_owner == 'PDAL' && github.event_name != 'pull_request' }}
steps:
- uses: actions/checkout@v6
- name: Lint
id: lint
run: |
echo "are we pushing packages" ${{ env.PUSH_PACKAGES }}
echo "event_name" ${{ github.event_name }}
echo "ref" ${{ github.ref }}
- name: Set up Docker
uses: docker/setup-docker-action@v5
with:
daemon-config: |
{
"debug": false,
"features": {
"containerd-snapshotter": true
}
}
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v4
with:
version: latest
- if: ${{ env.PUSH_PACKAGES == 'true' }}
name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- if: ${{ env.PUSH_PACKAGES == 'true' }}
name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract container metadata
id: meta
uses: docker/metadata-action@v6
with:
images: |
ghcr.io/pdal/pdal
docker.io/pdal/pdal
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
- name: Prepare
id: prep
run: |
VERSION=sha-${GITHUB_SHA::8}
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF/refs\/tags\//}
fi
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
runner=${{ matrix.runners }}
if [[ "$runner" == *"-arm" ]]; then
ARCH=arm64
else
ARCH=amd64
fi
echo "ARCH=$ARCH" >> $GITHUB_OUTPUT
- name: Build image
uses: docker/build-push-action@v7
id: push
with:
push: ${{ env.PUSH_PACKAGES == 'true' }}
builder: ${{ steps.buildx.outputs.name }}
file: "./scripts/docker/ubuntu/Dockerfile"
context: .
platforms: linux/${{ steps.prep.outputs.ARCH }}
# We need to pass in the SHA to the Dockerfile so it can checkout
# our code. It is a different active SHA depending on whether it is a
# PR or a simple push
build-args: |
GITHUB_SHA=${{ github.event.pull_request.head.sha != '' && github.event.pull_request.head.sha || github.sha }}
GITHUB_REPOSITORY=${{ github.event.pull_request.head.repo.full_name != '' && github.event.pull_request.head.repo.full_name || github.repository }}
tags: |
docker.io/pdal/pdal:${{ steps.prep.outputs.VERSION }}-${{ steps.prep.outputs.ARCH }}
docker.io/pdal/pdal:latest-${{ steps.prep.outputs.ARCH }}
ghcr.io/pdal/pdal:${{ steps.prep.outputs.VERSION }}-${{ steps.prep.outputs.ARCH }}
ghcr.io/pdal/pdal:latest-${{ steps.prep.outputs.ARCH }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }}
org.opencontainers.image.created=${{ steps.prep.outputs.BUILD_DATE }}
- name: Generate artifact attestation
if: ${{ env.PUSH_PACKAGES == 'true' }}
uses: actions/attest-build-provenance@v4
with:
subject-name: ghcr.io/pdal/pdal
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: ${{ env.PUSH_PACKAGES == 'true' }}
create-manifest:
permissions:
contents: read
packages: write
attestations: write
id-token: write
runs-on: ubuntu-latest
env:
PUSH_PACKAGES: ${{ github.repository_owner == 'PDAL' && github.event_name != 'pull_request' }}
needs: build_individual_images
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
if: env.PUSH_PACKAGES == 'true'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v4
if: env.PUSH_PACKAGES == 'true'
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create and push multi-platform manifest
if: env.PUSH_PACKAGES == 'true'
run: |
docker buildx imagetools create \
-t ghcr.io/pdal/pdal:latest \
ghcr.io/pdal/pdal:latest-amd64 \
ghcr.io/pdal/pdal:latest-arm64
docker buildx imagetools create \
-t pdal/pdal:latest \
pdal/pdal:latest-amd64 \
pdal/pdal:latest-arm64