Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bc06a6f
chore: write build_go.sh script and dependencies
deansheather Jun 7, 2022
850bc82
chore: write build_go_matrix.sh and archive.sh
deansheather Jun 8, 2022
e847230
fixup! chore: write build_go_matrix.sh and archive.sh
deansheather Jun 8, 2022
4edb649
fixup! chore: write build_go_matrix.sh and archive.sh
deansheather Jun 8, 2022
4ed419c
merge main
deansheather Jun 8, 2022
cef0221
chore: add scripts for packages
deansheather Jun 8, 2022
64f9648
chore: add scripts for building a docker image
deansheather Jun 8, 2022
998bc31
chore: add docker multi-arch script and release script
deansheather Jun 9, 2022
46b5d79
fixup! chore: add docker multi-arch script and release script
deansheather Jun 9, 2022
9e279a9
chore: fix indenting
deansheather Jun 9, 2022
4885076
chore: update makefile to use new build scripts
deansheather Jun 9, 2022
044780d
chore: update release workflow to use new build scripts
deansheather Jun 10, 2022
59cd2c7
fixup! chore: update release workflow to use new build scripts
deansheather Jun 12, 2022
d1edee5
fixup! chore: update release workflow to use new build scripts
deansheather Jun 12, 2022
4f03e37
fixup! chore: update release workflow to use new build scripts
deansheather Jun 12, 2022
5c9dd9e
fixup! chore: update release workflow to use new build scripts
deansheather Jun 12, 2022
e09edfd
fixup! chore: update release workflow to use new build scripts
deansheather Jun 13, 2022
4dd6f4d
chore: add dependency checks to release scripts
deansheather Jun 13, 2022
72d8b50
fixup! chore: add dependency checks to release scripts
deansheather Jun 13, 2022
17cda1f
fixup! chore: add dependency checks to release scripts
deansheather Jun 13, 2022
6a4bc44
fixup! chore: add dependency checks to release scripts
deansheather Jun 13, 2022
e150438
fixup! chore: add dependency checks to release scripts
deansheather Jun 13, 2022
449a1a1
chore: make dependency checks nicer
deansheather Jun 14, 2022
ba78076
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
a19ef36
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
94a6fcd
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
c524507
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
48eaa18
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
ce3f4f5
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
4886542
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
d4631ad
fixup! chore: make dependency checks nicer
deansheather Jun 14, 2022
a0c9a96
chore: integrate docker into pipeline
deansheather Jun 15, 2022
0907c37
fixup! chore: integrate docker into pipeline
deansheather Jun 15, 2022
4a94e25
fixup! chore: integrate docker into pipeline
deansheather Jun 16, 2022
37badc3
Merge branch 'main' into remove-goreleaser
deansheather Jun 16, 2022
173031f
chore: add version checks to lib.sh
deansheather Jun 16, 2022
ae48f20
fixup! chore: add version checks to lib.sh
deansheather Jun 16, 2022
d8a624c
fixup! chore: add version checks to lib.sh
deansheather Jun 16, 2022
6f2b997
Merge branch 'main' into remove-goreleaser
deansheather Jun 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add docker multi-arch script and release script
  • Loading branch information
deansheather committed Jun 9, 2022
commit 998bc31bce9f44bf5ca66b9eff8fcb2b6acfaefe
2 changes: 1 addition & 1 deletion scripts/archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ cdroot
rm -rf "$temp_dir"

if [[ "$sign_darwin" == 1 ]]; then
echo "Notarizing archive..."
log "Notarizing archive..."
execrelative ./sign_darwin.sh "$output_path"
fi

Expand Down
59 changes: 22 additions & 37 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,37 @@
# This script builds a Docker image of Coder containing the given binary, for
# the given architecture. Only linux binaries are supported at this time.
#
# Usage: ./build_docker.sh --arch amd64 --tags v1.2.4-rc.1-arm64,v1.2.3+devel.abcdef [--version 1.2.3] [--push]
# Usage: ./build_docker.sh --arch amd64 [--version 1.2.3] [--push]
#
# The --arch parameter is required and accepts a Golang arch specification. It
# will be automatically mapped to a suitable architecture that Docker accepts.
# will be automatically mapped to a suitable architecture that Docker accepts
# before being passed to `docker buildx build`.
#
# The image will be built and tagged against all supplied tags. At least one tag
# must be supplied. All tags will be sanitized to remove invalid characters like
# plus signs.
# The image will be built and tagged against the image tag returned by
# ./image_tag.sh.
#
# If no version is specified, defaults to the version from ./version.sh.
#
# If the --push parameter is supplied, all supplied tags will be pushed.
# If the --push parameter is supplied, the image will be pushed.
#
# Prints the image tag on success.

set -euo pipefail
# shellcheck source=lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

image="ghcr.io/coder/coder"
arch=""
tags_str=""
version=""
push=0

args="$(getopt -o "" -l arch:,tags:,version:,push -- "$@")"
args="$(getopt -o "" -l arch:,version:,push -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
--arch)
arch="$2"
shift 2
;;
--tags)
tags_str="$2"
shift 2
;;
--version)
version="$2"
shift 2
Expand All @@ -60,16 +56,14 @@ if [[ "$arch" == "" ]]; then
error "The --arch parameter is required"
fi

tags=()
for tag in $(echo "$tags_str" | tr "," "\n"); do
# Docker images don't support plus signs, which devel versions may contain.
tag="${tag//+/-}"
tags+=("$tag")
done
if [[ "${#tags[@]}" == 0 ]]; then
error "At least one tag must be supplied through --tags"
# Remove the "v" prefix.
version="${version#v}"
if [[ "$version" == "" ]]; then
version="$(execrelative ./version.sh)"
fi

image_tag="$(execrelative ./image_tag.sh --arch "$arch" --version="$version")"

if [[ "$#" != 1 ]]; then
error "Exactly one argument must be provided to this script, $# were supplied"
fi
Expand All @@ -78,12 +72,6 @@ if [[ ! -f "$1" ]]; then
fi
input_file="$(realpath "$1")"

# Remove the "v" prefix.
version="${version#v}"
if [[ "$version" == "" ]]; then
version="$(execrelative ./version.sh)"
fi

# Remap the arch from Golang to Docker.
declare -A arch_map=(
[amd64]="linux/amd64"
Expand Down Expand Up @@ -111,21 +99,18 @@ build_args=(
"--label=org.opencontainers.image.source=https://github.com/coder/coder"
"--label=org.opencontainers.image.version=$version"
"--label=org.opencontainers.image.licenses=AGPL-3.0"
"--tag=$image_tag"
)
for tag in "${tags[@]}"; do
build_args+=(--tag "$image:$tag")
done

echo "--- Building Docker image for $arch"
docker buildx build "${build_args[@]}" .
log "--- Building Docker image for $arch ($image_tag)"
docker buildx build "${build_args[@]}" . 1>&2

cdroot
rm -rf "$temp_dir"

if [[ "$push" == 1 ]]; then
echo "--- Pushing Docker images for $arch"
for tag in "${tags[@]}"; do
echo "Pushing $image:$tag"
docker push "$image:$tag"
done
log "--- Pushing Docker image for $arch ($image_tag)"
docker push "$image_tag"
fi

echo -n "$image_tag"
73 changes: 73 additions & 0 deletions scripts/build_docker_multiarch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

# This script merges Coder Docker images of different architectures together
# into the archless image tag returned by ./image_tag.sh.
#
# Usage: ./build_docker_multiarch.sh [--version 1.2.3] [--push] image1:tag1 image2:tag2
#
# The supplied images must already be pushed to the registry or this will fail.
# Also, the source images cannot be in a different registry than the target
# image generated by ./image_tag.sh.
#
# If no version is specified, defaults to the version from ./version.sh.
#
# If the --push parameter is supplied, all supplied tags will be pushed.
#
# Returns the merged image tag.

set -euo pipefail
# shellcheck source=lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

version=""
push=0

args="$(getopt -o "" -l version:,push -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
--version)
version="$2"
shift 2
;;
--push)
push=1
shift
;;
--)
shift
break
;;
*)
error "Unrecognized option: $1"
;;
esac
done

# Remove the "v" prefix.
version="${version#v}"
if [[ "$version" == "" ]]; then
version="$(execrelative ./version.sh)"
fi

if [[ "$#" == 0 ]]; then
error "At least one argument must be provided to this script, $# were supplied"
fi

create_args=()
for image_tag in "$@"; do
create_args+=(--amend "$image_tag")
done

output_tag="$(execrelative ./image_tag.sh --version "$version")"
log "--- Creating multi-arch Docker image ($output_tag)"
docker manifest create \
"$output_tag" \
"${create_args[@]}"

if [[ "$push" == 1 ]]; then
log "--- Pushing multi-arch Docker image ($output_tag)"
docker push "$output_tag"
fi

echo -n "$output_tag"
14 changes: 7 additions & 7 deletions scripts/build_go_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ for spec in "${specs[@]}"; do
# Ensure parent dir.
mkdir -p "$(dirname "$spec_output")"

echo "--- Building coder for $spec_os $spec_arch ($spec_output_binary)"
log "--- Building coder for $spec_os $spec_arch ($spec_output_binary)"
execrelative ./build_go.sh \
--version "$version" \
--os "$spec_os" \
--arch "$spec_arch" \
--output "$spec_output_binary" \
"${build_args[@]}"
echo
echo
log
log

if [[ "$archive" == 1 ]]; then
spec_archive_format="tar.gz"
Expand All @@ -177,21 +177,21 @@ for spec in "${specs[@]}"; do
archive_args+=(--sign-darwin)
fi

echo "--- Creating archive for $spec_os $spec_arch ($spec_output_archive)"
log "--- Creating archive for $spec_os $spec_arch ($spec_output_archive)"
execrelative ./archive.sh \
--format "$spec_archive_format" \
--output "$spec_output_archive" \
"${archive_args[@]}" \
"$spec_output_binary"
echo
echo
log
log
fi

if [[ "$package_linux" == 1 ]] && [[ "$spec_os" == "linux" ]]; then
execrelative ./package.sh \
--arch "$spec_arch" \
--version "$version" \
"$spec_output_binary"
echo
log
fi
done
58 changes: 58 additions & 0 deletions scripts/image_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

# This script prints the image tag to use for the given arch and version
# combination.
#
# Usage: ./image_tag.sh [--arch amd64] [--version 1.2.3]
#
# The --arch parameter accepts a Golang arch specification. If not specified,
# the image tag for the multi-arch image will be returned instead.
#
# If no version is specified, defaults to the version from ./version.sh.
#
# The returned tag will be sanitized to remove invalid characters like the plus
# sign.

set -euo pipefail
# shellcheck source=lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

arch=""
version=""

args="$(getopt -o "" -l arch:,version: -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
--arch)
arch="$2"
shift 2
;;
--version)
version="$2"
shift 2
;;
--)
shift
break
;;
*)
error "Unrecognized option: $1"
;;
esac
done

# Remove the "v" prefix.
version="${version#v}"
if [[ "$version" == "" ]]; then
version="$(execrelative ./version.sh)"
fi

image="${CODER_IMAGE_BASE:-ghcr.io/coder/coder}"
tag="v$version"
if [[ "$arch" != "" ]]; then
tag+="-$arch"
fi

tag="${tag//+/-}"
echo -n "$image:$tag"
26 changes: 25 additions & 1 deletion scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,32 @@ realpath() {
)"/"$base"
}

# maybedryrun prints the given program and flags, and then, if the first
# argument is 0, executes it. The reason the first argument should be 0 is that
# it is expected that you have a dry_run variable in your script that is set to
# 0 by default (i.e. do not dry run) and set to 1 if the --dry-run flag is
# specified.
#
# Usage: maybedryrun 1 gh release create ...
# Usage: maybedryrun 0 docker push ghcr.io/coder/coder:latest
maybedryrun() {
if [[ "$1" == 1 ]]; then
shift
log "DRYRUN: $*"
else
shift
log $ "$@"
"$@"
fi
}

# log prints a message to stderr.
log() {
echo "$*" 1>&2
}

# error prints an error message and returns an error exit code.
error() {
echo "ERROR: $*" 1>&2
log "ERROR: $*"
exit 1
}
2 changes: 1 addition & 1 deletion scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cd "$temp_dir"
formats=(apk deb rpm)
for format in "${formats[@]}"; do
output_path="$input_file.$format"
echo "--- Building $format package ($output_path)"
log "--- Building $format package ($output_path)"
nfpm package \
-f nfpm.yaml \
-p "$format" \
Expand Down
Loading