Skip to content

Commit 69d9f1f

Browse files
committed
code images: Use kaniko
1 parent 89540cf commit 69d9f1f

File tree

1 file changed

+101
-120
lines changed

1 file changed

+101
-120
lines changed

.github/workflows/code-ubuntu.yaml

Lines changed: 101 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -3,160 +3,141 @@ on:
33
schedule:
44
- cron: "0 10 * * *"
55
push:
6-
branches:
7-
- "**"
8-
tags:
9-
- "v*.*.*"
6+
branches: ["**"]
7+
tags: ["v*.*.*"]
108
pull_request:
11-
branches:
12-
- "main"
9+
branches: [main]
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_PREFIX: ghcr.io/${{ github.repository }}/code
13+
KANIKO_EXTRA_ARGS: >-
14+
--snapshot-mode=redo --use-new-run --cache-run-layers --cache-copy-layers --cache-ttl=168h --compressed-caching=false --cleanup
1315
jobs:
14-
build:
16+
build-base:
1517
strategy:
1618
fail-fast: false
1719
matrix:
1820
image:
1921
- name: ubuntu
2022
context: images/base
21-
dockerfile: ubuntu.Dockerfile
23+
- name: minimal
24+
context: images/minimal
25+
platform:
26+
- runner: ubuntu-latest
27+
arch: amd64
28+
- runner: ubuntu-24.04-arm
29+
arch: arm64
30+
runs-on: ${{ matrix.platform.runner }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
repository: coder/images
35+
submodules: recursive
36+
- uses: aevea/action-kaniko@master
37+
with:
38+
image: code/${{ matrix.image.name }}
39+
path: ${{ matrix.image.context }}
40+
build_file: ubuntu.Dockerfile
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
cache: true
45+
cache_registry: code/${{ matrix.image.name }}/cache
46+
extra_args: ${{ env.KANIKO_EXTRA_ARGS }}
47+
manifest-base:
48+
needs: build-base
49+
if: github.event_name != 'pull_request'
50+
runs-on: ubuntu-latest
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
image: [ubuntu, minimal]
55+
steps:
56+
- uses: imjasonh/setup-crane@v0.4
57+
- name: Push manifest
58+
run: |
59+
crane auth login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
60+
61+
IMAGE="${{ env.IMAGE_PREFIX }}/${{ matrix.image }}"
62+
TAGS="latest ${{ github.sha }}"
63+
64+
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
65+
TAGS="$TAGS ${{ github.ref_name }}"
66+
fi
67+
68+
for TAG in $TAGS; do
69+
crane index append \
70+
--tag "${IMAGE}:${TAG}" \
71+
--manifest "${IMAGE}:latest-amd64" \
72+
--manifest "${IMAGE}:latest-arm64"
73+
done
74+
build-derived:
75+
needs: manifest-base
76+
if: always() && !failure() && !cancelled()
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
image:
2281
- name: desktop
2382
context: images/desktop
24-
dockerfile: ubuntu.Dockerfile
2583
- name: golang
2684
context: images/golang
27-
dockerfile: ubuntu.Dockerfile
2885
- name: java
2986
context: images/java
30-
dockerfile: ubuntu.Dockerfile
31-
- name: minimal
32-
context: images/minimal
33-
dockerfile: ubuntu.Dockerfile
3487
- name: node
3588
context: images/node
36-
dockerfile: ubuntu.Dockerfile
3789
platform:
3890
- runner: ubuntu-latest
39-
arch: linux/amd64
91+
arch: amd64
4092
- runner: ubuntu-24.04-arm
41-
arch: linux/arm64
93+
arch: arm64
4294
runs-on: ${{ matrix.platform.runner }}
4395
steps:
44-
- name: Set variables useful for later
45-
id: useful_vars
46-
run: |
47-
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
48-
echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
49-
- name: Checkout
50-
uses: actions/checkout@v4
96+
- uses: actions/checkout@v4
5197
with:
5298
repository: coder/images
5399
submodules: recursive
54-
- name: Docker meta
55-
id: docker_meta
56-
uses: docker/metadata-action@v5
57-
with:
58-
images: ghcr.io/${{ github.repository }}/code/${{ matrix.image.name }}
59-
tags: |
60-
type=schedule
61-
type=ref,event=branch
62-
type=ref,event=pr
63-
type=semver,pattern={{version}}
64-
type=semver,pattern={{major}}.{{minor}}
65-
type=semver,pattern={{major}}
66-
type=sha,prefix=,format=long,event=tag
67-
type=sha
68-
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
69-
type=raw,value=${{ github.ref_name }}-${{ steps.useful_vars.outputs.short_sha }}-${{ steps.useful_vars.outputs.timestamp }},enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
70-
flavor: |
71-
suffix=-${{ matrix.platform.arch == 'linux/amd64' && 'amd64' || 'arm64' }}
72-
- name: Set up Docker Buildx
73-
uses: docker/setup-buildx-action@v3
74-
- name: Login to GHCR
75-
if: github.event_name != 'pull_request'
76-
uses: docker/login-action@v3
100+
- name: Point to our base images
101+
run: |
102+
sed -i \
103+
-e 's|codercom/enterprise-base:ubuntu|${{ env.IMAGE_PREFIX }}/ubuntu:latest|g' \
104+
-e 's|codercom/enterprise-minimal:latest|${{ env.IMAGE_PREFIX }}/minimal:latest|g' \
105+
${{ matrix.image.context }}/ubuntu.Dockerfile
106+
- uses: aevea/action-kaniko@master
77107
with:
78-
registry: ghcr.io
79-
username: ${{ github.repository_owner }}
108+
image: code/${{ matrix.image.name }}
109+
path: ${{ matrix.image.context }}
110+
build_file: ubuntu.Dockerfile
111+
registry: ${{ env.REGISTRY }}
112+
username: ${{ github.actor }}
80113
password: ${{ secrets.GITHUB_TOKEN }}
81-
- name: Cache Docker layers
82-
uses: actions/cache@v4
83-
with:
84-
path: /tmp/.buildx-cache
85-
key: ${{ runner.os }}-${{ matrix.image.name }}-${{ matrix.platform.arch }}-buildx-${{ github.sha }}
86-
restore-keys: |
87-
${{ runner.os }}-${{ matrix.image.name }}-${{ matrix.platform.arch }}-buildx-
88-
- name: Build and push
89-
uses: docker/build-push-action@v6
90-
with:
91-
context: ${{ matrix.image.context }}
92-
file: ${{ matrix.image.context }}/${{ matrix.image.dockerfile }}
93-
push: ${{ github.event_name != 'pull_request' }}
94-
tags: ${{ steps.docker_meta.outputs.tags }}
95-
labels: ${{ steps.docker_meta.outputs.labels }}
96-
platforms: ${{ matrix.platform.arch }}
97-
cache-from: type=local,src=/tmp/.buildx-cache
98-
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
99-
# Create multi-arch manifests after all platform builds complete
100-
manifest:
101-
needs: build
114+
cache: true
115+
cache_registry: code/${{ matrix.image.name }}/cache
116+
extra_args: ${{ env.KANIKO_EXTRA_ARGS }}
117+
manifest-derived:
118+
needs: build-derived
102119
if: github.event_name != 'pull_request'
103120
runs-on: ubuntu-latest
104121
strategy:
105122
fail-fast: false
106123
matrix:
107-
image:
108-
- ubuntu
109-
- desktop
110-
- golang
111-
- java
112-
- minimal
113-
- node
124+
image: [desktop, golang, java, node]
114125
steps:
115-
- name: Set variables useful for later
116-
id: useful_vars
117-
run: |
118-
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
119-
echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
120-
- name: Login to GHCR
121-
uses: docker/login-action@v3
122-
with:
123-
registry: ghcr.io
124-
username: ${{ github.repository_owner }}
125-
password: ${{ secrets.GITHUB_TOKEN }}
126-
- name: Docker meta
127-
id: docker_meta
128-
uses: docker/metadata-action@v5
129-
with:
130-
images: ghcr.io/${{ github.repository }}/code/${{ matrix.image }}
131-
tags: |
132-
type=schedule
133-
type=ref,event=branch
134-
type=ref,event=pr
135-
type=semver,pattern={{version}}
136-
type=semver,pattern={{major}}.{{minor}}
137-
type=semver,pattern={{major}}
138-
type=sha,prefix=,format=long,event=tag
139-
type=sha
140-
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
141-
type=raw,value=${{ github.ref_name }}-${{ steps.useful_vars.outputs.short_sha }}-${{ steps.useful_vars.outputs.timestamp }},enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
142-
- name: Create and push manifest
126+
- uses: imjasonh/setup-crane@v0.4
127+
- name: Push manifest
143128
run: |-
144-
TAGS="${{ steps.docker_meta.outputs.tags }}"
145-
IMAGE_BASE="ghcr.io/${{ github.repository }}/code/${{ matrix.image }}"
146-
147-
for TAG in $TAGS; do
148-
# Extract just the tag portion after the colon
149-
TAG_NAME="${TAG##*:}"
129+
crane auth login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
150130
151-
docker manifest create "${IMAGE_BASE}:${TAG_NAME}" \
152-
"${IMAGE_BASE}:${TAG_NAME}-amd64" \
153-
"${IMAGE_BASE}:${TAG_NAME}-arm64"
131+
IMAGE="${{ env.IMAGE_PREFIX }}/${{ matrix.image }}"
132+
TAGS="latest ${{ github.sha }}"
154133
155-
docker manifest annotate "${IMAGE_BASE}:${TAG_NAME}" \
156-
"${IMAGE_BASE}:${TAG_NAME}-amd64" --arch amd64
134+
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
135+
TAGS="$TAGS ${{ github.ref_name }}"
136+
fi
157137
158-
docker manifest annotate "${IMAGE_BASE}:${TAG_NAME}" \
159-
"${IMAGE_BASE}:${TAG_NAME}-arm64" --arch arm64
160-
161-
docker manifest push "${IMAGE_BASE}:${TAG_NAME}"
138+
for TAG in $TAGS; do
139+
crane index append \
140+
--tag "${IMAGE}:${TAG}" \
141+
--manifest "${IMAGE}:latest-amd64" \
142+
--manifest "${IMAGE}:latest-arm64"
162143
done

0 commit comments

Comments
 (0)