Skip to content

Commit 14d1b8d

Browse files
committed
code images: Use kaniko
1 parent 89540cf commit 14d1b8d

File tree

1 file changed

+72
-110
lines changed

1 file changed

+72
-110
lines changed

.github/workflows/code-ubuntu.yaml

Lines changed: 72 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -11,152 +11,114 @@ on:
1111
branches:
1212
- "main"
1313
jobs:
14-
build:
14+
build-base:
1515
strategy:
1616
fail-fast: false
1717
matrix:
1818
image:
1919
- name: ubuntu
2020
context: images/base
21-
dockerfile: ubuntu.Dockerfile
21+
- name: minimal
22+
context: images/minimal
23+
platform:
24+
- runner: ubuntu-latest
25+
arch: amd64
26+
- runner: ubuntu-24.04-arm
27+
arch: arm64
28+
runs-on: ${{ matrix.platform.runner }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
with:
33+
repository: coder/images
34+
submodules: recursive
35+
- name: Build and push with Kaniko
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: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
cache: true
45+
cache_registry: ${{ matrix.image.name }}/cache
46+
extra_args: >-
47+
--snapshot-mode=redo --use-new-run --cache-run-layers --cache-copy-layers --cache-ttl=168h --compressed-caching=false --cleanup
48+
kaniko_image: martizih/kaniko:latest
49+
build-derived:
50+
needs: build-base
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
image:
2255
- name: desktop
2356
context: images/desktop
24-
dockerfile: ubuntu.Dockerfile
2557
- name: golang
2658
context: images/golang
27-
dockerfile: ubuntu.Dockerfile
2859
- name: java
2960
context: images/java
30-
dockerfile: ubuntu.Dockerfile
31-
- name: minimal
32-
context: images/minimal
33-
dockerfile: ubuntu.Dockerfile
3461
- name: node
3562
context: images/node
36-
dockerfile: ubuntu.Dockerfile
3763
platform:
3864
- runner: ubuntu-latest
39-
arch: linux/amd64
65+
arch: amd64
4066
- runner: ubuntu-24.04-arm
41-
arch: linux/arm64
67+
arch: arm64
4268
runs-on: ${{ matrix.platform.runner }}
4369
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
4970
- name: Checkout
5071
uses: actions/checkout@v4
5172
with:
5273
repository: coder/images
5374
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
75+
- name: Replace base image references
76+
run: |
77+
DOCKERFILE="${{ matrix.image.context }}/ubuntu.Dockerfile"
78+
sed -i 's|codercom/enterprise-base:ubuntu|ghcr.io/${{ github.repository }}/ubuntu:latest|g' "$DOCKERFILE"
79+
sed -i 's|codercom/enterprise-minimal:latest|ghcr.io/${{ github.repository }}/minimal:latest|g' "$DOCKERFILE"
80+
- name: Build and push with Kaniko
81+
uses: aevea/action-kaniko@master
7782
with:
83+
image: code/${{ matrix.image.name }}
84+
path: ${{ matrix.image.context }}
85+
build_file: ubuntu.Dockerfile
7886
registry: ghcr.io
79-
username: ${{ github.repository_owner }}
87+
username: ${{ github.actor }}
8088
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
89+
cache: true
90+
cache_registry: ${{ matrix.image.name }}/cache
91+
extra_args: >-
92+
--snapshot-mode=redo --use-new-run --cache-run-layers --cache-copy-layers --cache-ttl=168h --compressed-caching=false --cleanup
93+
kaniko_image: martizih/kaniko:latest
10094
manifest:
101-
needs: build
95+
needs: [build-base, build-derived]
10296
if: github.event_name != 'pull_request'
10397
runs-on: ubuntu-latest
10498
strategy:
10599
fail-fast: false
106100
matrix:
107-
image:
108-
- ubuntu
109-
- desktop
110-
- golang
111-
- java
112-
- minimal
113-
- node
101+
image: [ubuntu, minimal, desktop, golang, java, node]
114102
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
103+
- name: Setup crane
104+
uses: imjasonh/setup-crane@v0.4
120105
- 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) }}
106+
run: crane auth login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
142107
- name: Create and push manifest
143108
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##*:}"
109+
IMAGE="ghcr.io/${{ github.repository }}/${{ matrix.image }}"
150110
151-
docker manifest create "${IMAGE_BASE}:${TAG_NAME}" \
152-
"${IMAGE_BASE}:${TAG_NAME}-amd64" \
153-
"${IMAGE_BASE}:${TAG_NAME}-arm64"
154-
155-
docker manifest annotate "${IMAGE_BASE}:${TAG_NAME}" \
156-
"${IMAGE_BASE}:${TAG_NAME}-amd64" --arch amd64
157-
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}"
111+
for TAG in latest ${{ github.sha }}; do
112+
crane index append \
113+
--tag "${IMAGE}:${TAG}" \
114+
--manifest "${IMAGE}:${TAG}-amd64" \
115+
--manifest "${IMAGE}:${TAG}-arm64"
162116
done
117+
118+
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
119+
VERSION="${{ github.ref_name }}"
120+
crane index append \
121+
--tag "${IMAGE}:${VERSION}" \
122+
--manifest "${IMAGE}:${VERSION}-amd64" \
123+
--manifest "${IMAGE}:${VERSION}-arm64"
124+
fi

0 commit comments

Comments
 (0)