Skip to content

Commit a0c9a96

Browse files
committed
chore: integrate docker into pipeline
1 parent d4631ad commit a0c9a96

File tree

5 files changed

+65
-14
lines changed

5 files changed

+65
-14
lines changed

.github/workflows/release.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858

5959
- name: Build Linux and Windows Binaries
6060
run: |
61+
set -euo pipefail
6162
go mod download
6263
6364
mkdir -p ./dist
@@ -76,6 +77,37 @@ jobs:
7677
linux:amd64,armv7,arm64 \
7778
windows:amd64,arm64
7879
80+
- name: Build Linux Docker images
81+
run: |
82+
set -euo pipefail
83+
84+
# build and push Docker images for each architecture
85+
images=()
86+
for arch in amd64 armv7 arm64; do
87+
img="$(
88+
./scripts/build_docker.sh \
89+
${{ !github.event.inputs.dry_run && !github.event.inputs.snapshot && '--push' }} \
90+
--arch "$arch" \
91+
./dist/coder_*_linux_"$arch"
92+
)"
93+
images+=("$img")
94+
done
95+
96+
# build and push multi-arch manifest
97+
./scripts/build_docker_multiarch.sh \
98+
${{ !github.event.inputs.dry_run && !github.event.inputs.snapshot && '--push' }} \
99+
"${images[@]}"
100+
101+
# if the current version is equal to the highest (according to semver)
102+
# version in the repo, also create a multi-arch image as ":latest" and
103+
# push it
104+
if [[ "$(git tag | grep '^v' | grep -vE '(rc|dev|-|\+|\/)' | sort -r --version-sort | head -n1)" == "v$(./scripts/version.sh)" ]]; then
105+
./scripts/build_docker_multiarch.sh \
106+
--target "$(./scripts/image_tag.sh --version latest)" \
107+
${{ !github.event.inputs.dry_run && !github.event.inputs.snapshot && '--push' }} \
108+
"${images[@]}"
109+
fi
110+
79111
- name: Upload binary artifacts
80112
uses: actions/upload-artifact@v3
81113
with:
@@ -120,6 +152,7 @@ jobs:
120152
121153
- name: Install dependencies
122154
run: |
155+
set -euo pipefail
123156
# The version of bash that MacOS ships with is too old
124157
brew install bash
125158
@@ -140,6 +173,7 @@ jobs:
140173

141174
- name: Build darwin Binaries (with signatures)
142175
run: |
176+
set -euo pipefail
143177
go mod download
144178
145179
mkdir -p ./dist

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.9"
22
services:
33
coder:
4-
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.10}
4+
image: ghcr.io/coder/coder:v${CODER_VERSION:-latest}
55
ports:
66
- "7080:7080"
77
environment:

scripts/build_docker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This script builds a Docker image of Coder containing the given binary, for
44
# the given architecture. Only linux binaries are supported at this time.
55
#
6-
# Usage: ./build_docker.sh --arch amd64 [--version 1.2.3] [--push]
6+
# Usage: ./build_docker.sh --arch amd64 [--version 1.2.3] [--push] path/to/coder
77
#
88
# The --arch parameter is required and accepts a Golang arch specification. It
99
# will be automatically mapped to a suitable architecture that Docker accepts
@@ -80,6 +80,7 @@ declare -A arch_map=(
8080
[amd64]="linux/amd64"
8181
[arm64]="linux/arm64"
8282
[arm]="linux/arm/v7"
83+
[armv7]="linux/arm/v7"
8384
)
8485
if [[ "${arch_map[$arch]+exists}" != "" ]]; then
8586
arch="${arch_map[$arch]}"

scripts/build_docker_multiarch.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#!/usr/bin/env bash
22

33
# This script merges Coder Docker images of different architectures together
4-
# into the archless image tag returned by ./image_tag.sh.
4+
# into the specified target image+tag, or the arch-less image tag returned by
5+
# ./image_tag.sh.
56
#
6-
# Usage: ./build_docker_multiarch.sh [--version 1.2.3] [--push] image1:tag1 image2:tag2
7+
# Usage: ./build_docker_multiarch.sh [--version 1.2.3] [--target image:tag] [--push] image1:tag1 image2:tag2
78
#
89
# The supplied images must already be pushed to the registry or this will fail.
910
# Also, the source images cannot be in a different registry than the target
10-
# image generated by ./image_tag.sh.
11+
# image.
1112
#
1213
# If no version is specified, defaults to the version from ./version.sh.
1314
#
15+
# If no target tag is supplied, the arch-less image tag returned by
16+
# ./image_tag.sh will be used.
17+
#
1418
# If the --push parameter is supplied, all supplied tags will be pushed.
1519
#
1620
# Returns the merged image tag.
@@ -20,16 +24,21 @@ set -euo pipefail
2024
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
2125

2226
version=""
27+
target=""
2328
push=0
2429

25-
args="$(getopt -o "" -l version:,push -- "$@")"
30+
args="$(getopt -o "" -l version:,target:,push -- "$@")"
2631
eval set -- "$args"
2732
while true; do
2833
case "$1" in
2934
--version)
3035
version="$2"
3136
shift 2
3237
;;
38+
--target)
39+
target="$2"
40+
shift 2
41+
;;
3342
--push)
3443
push=1
3544
shift
@@ -57,21 +66,24 @@ if [[ "$version" == "" ]]; then
5766
version="$(execrelative ./version.sh)"
5867
fi
5968

69+
if [[ "$target" == "" ]]; then
70+
target="$(execrelative ./image_tag.sh --version "$version")"
71+
fi
72+
6073
create_args=()
6174
for image_tag in "$@"; do
6275
create_args+=(--amend "$image_tag")
6376
done
6477

6578
# Sadly, multi-arch images don't seem to support labels.
66-
output_tag="$(execrelative ./image_tag.sh --version "$version")"
67-
log "--- Creating multi-arch Docker image ($output_tag)"
79+
log "--- Creating multi-arch Docker image ($target)"
6880
docker manifest create \
69-
"$output_tag" \
81+
"$target" \
7082
"${create_args[@]}"
7183

7284
if [[ "$push" == 1 ]]; then
73-
log "--- Pushing multi-arch Docker image ($output_tag)"
74-
docker push "$output_tag"
85+
log "--- Pushing multi-arch Docker image ($target)"
86+
docker manifest push "$target"
7587
fi
7688

77-
echo "$output_tag"
89+
echo "$target"

scripts/image_tag.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# The --arch parameter accepts a Golang arch specification. If not specified,
99
# the image tag for the multi-arch image will be returned instead.
1010
#
11-
# If no version is specified, defaults to the version from ./version.sh.
11+
# If no version is specified, defaults to the version from ./version.sh. If the
12+
# supplied version is "latest", no `v` prefix will be added to the tag.
1213
#
1314
# The returned tag will be sanitized to remove invalid characters like the plus
1415
# sign.
@@ -42,14 +43,17 @@ while true; do
4243
esac
4344
done
4445

45-
# Remove the "v" prefix.
46+
# Remove the "v" prefix because we don't want to add it twice.
4647
version="${version#v}"
4748
if [[ "$version" == "" ]]; then
4849
version="$(execrelative ./version.sh)"
4950
fi
5051

5152
image="${CODER_IMAGE_BASE:-ghcr.io/coder/coder}"
5253
tag="v$version"
54+
if [[ "$version" == "latest" ]]; then
55+
tag="latest"
56+
fi
5357
if [[ "$arch" != "" ]]; then
5458
tag+="-$arch"
5559
fi

0 commit comments

Comments
 (0)