Skip to content

Remove goreleaser in favor of build scripts #2143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jun 18, 2022
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 scripts for building a docker image
  • Loading branch information
deansheather committed Jun 8, 2022
commit 64f9648f5de2dc110c156bb301b35cb8abc1df09
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine

# Generated by goreleaser on `goreleaser release`
# The coder binary is injected by scripts/build_docker.sh.
ADD coder /opt/coder

ENTRYPOINT [ "/opt/coder", "server" ]
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.9"
services:
coder:
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.10}-${ARCH:-amd64}
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.10}
ports:
- "7080:7080"
environment:
Expand Down
131 changes: 131 additions & 0 deletions scripts/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env bash

# 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]
#
# The --arch parameter is required and accepts a Golang arch specification. It
# will be automatically mapped to a suitable architecture that Docker accepts.
#
# 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.
#
# If no version is specified, defaults to the version from ./version.sh.
#
# If the --push parameter is supplied, all supplied tags will be pushed.

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 -- "$@")"
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
;;
--push)
push=1
shift
;;
--)
shift
break
;;
*)
error "Unrecognized option: $1"
;;
esac
done

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"
fi

if [[ "$#" != 1 ]]; then
error "Exactly one argument must be provided to this script, $# were supplied"
fi
if [[ ! -f "$1" ]]; then
error "File '$1' does not exist or is not a regular file"
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"
[arm64]="linux/arm64"
[arm]="linux/arm/v7"
)
if [[ "${arch_map[$arch]+exists}" != "" ]]; then
arch="${arch_map[$arch]}"
fi

# Make temporary dir where all source files intended to be in the image will be
# hardlinked from.
cdroot
temp_dir="$(TMPDIR="$(dirname "$input_file")" mktemp -d)"
ln -P "$input_file" "$temp_dir/coder"
ln -P Dockerfile "$temp_dir/"

cd "$temp_dir"

build_args=(
"--platform=$arch"
"--label=org.opencontainers.image.title=Coder"
"--label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform."
"--label=org.opencontainers.image.url=https://github.com/coder/coder"
"--label=org.opencontainers.image.source=https://github.com/coder/coder"
"--label=org.opencontainers.image.version=$version"
"--label=org.opencontainers.image.licenses=AGPL-3.0"
)
for tag in "${tags[@]}"; do
build_args+=(--tag "$image:$tag")
done

echo "--- Building Docker image for $arch"
docker buildx build "${build_args[@]}" .

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
fi
1 change: 1 addition & 0 deletions scripts/build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if [[ "$output_path" == "" ]]; then
fi
build_args+=(-o "$output_path")

# TODO: GOARM
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
"${build_args[@]}" \
./cmd/coder 1>&2
Expand Down
1 change: 1 addition & 0 deletions scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ realpath() {
)"/"$base"
}

# error prints an error message and returns an error exit code.
error() {
echo "ERROR: $*" 1>&2
exit 1
Expand Down
1 change: 1 addition & 0 deletions scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ for format in "${formats[@]}"; do
-t "$output_path"
done

cdroot
rm -rf "$temp_dir"