Skip to content

Commit 89540cf

Browse files
committed
Add code ubuntu images
1 parent 8e8fc86 commit 89540cf

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

.github/workflows/code-ubuntu.yaml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
name: code-ubuntu
2+
on:
3+
schedule:
4+
- cron: "0 10 * * *"
5+
push:
6+
branches:
7+
- "**"
8+
tags:
9+
- "v*.*.*"
10+
pull_request:
11+
branches:
12+
- "main"
13+
jobs:
14+
build:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
image:
19+
- name: ubuntu
20+
context: images/base
21+
dockerfile: ubuntu.Dockerfile
22+
- name: desktop
23+
context: images/desktop
24+
dockerfile: ubuntu.Dockerfile
25+
- name: golang
26+
context: images/golang
27+
dockerfile: ubuntu.Dockerfile
28+
- name: java
29+
context: images/java
30+
dockerfile: ubuntu.Dockerfile
31+
- name: minimal
32+
context: images/minimal
33+
dockerfile: ubuntu.Dockerfile
34+
- name: node
35+
context: images/node
36+
dockerfile: ubuntu.Dockerfile
37+
platform:
38+
- runner: ubuntu-latest
39+
arch: linux/amd64
40+
- runner: ubuntu-24.04-arm
41+
arch: linux/arm64
42+
runs-on: ${{ matrix.platform.runner }}
43+
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
51+
with:
52+
repository: coder/images
53+
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
77+
with:
78+
registry: ghcr.io
79+
username: ${{ github.repository_owner }}
80+
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
102+
if: github.event_name != 'pull_request'
103+
runs-on: ubuntu-latest
104+
strategy:
105+
fail-fast: false
106+
matrix:
107+
image:
108+
- ubuntu
109+
- desktop
110+
- golang
111+
- java
112+
- minimal
113+
- node
114+
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
143+
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##*:}"
150+
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}"
162+
done

0 commit comments

Comments
 (0)