2022-09-07 16:40:17 +00:00
# This is the Coder Makefile. The build directory for most tasks is `build/`.
#
# These are the targets you're probably looking for:
# - clean
# - build-fat: builds all "fat" binaries for all architectures
# - build-slim: builds all "slim" binaries (no frontend or slim binaries
# embedded) for all architectures
# - release: simulate a release (mostly, does not push images)
# - build/coder(-slim)?_${os}_${arch}(.exe)?: build a single fat binary
# - build/coder_${os}_${arch}.(zip|tar.gz): build a release archive
# - build/coder_linux_${arch}.(apk|deb|rpm): build a release Linux package
# - build/coder_${version}_linux_${arch}.tag: build a release Linux Docker image
# - build/coder_helm.tgz: build a release Helm chart
.DEFAULT_GOAL := build-fat
2022-05-02 19:04:45 +00:00
2022-06-18 19:47:10 +00:00
# Use a single bash shell for each job, and immediately exit on failure
SHELL := bash
2022-09-07 16:40:17 +00:00
.SHELLFLAGS := -ceu
2022-06-18 19:47:10 +00:00
.ONESHELL :
# This doesn't work on directories.
# See https://stackoverflow.com/questions/25752543/make-delete-on-error-for-directory-targets
.DELETE_ON_ERROR :
2022-09-07 16:40:17 +00:00
# Don't print the commands in the file unless you specify VERBOSE. This is
# essentially the same as putting "@" at the start of each line.
i f n d e f V E R B O S E
.SILENT :
e n d i f
2022-05-02 19:04:45 +00:00
2022-09-07 16:40:17 +00:00
# Create the output directories if they do not exist.
$( shell mkdir -p build site /out /bin )
GOOS := $( shell go env GOOS)
GOARCH := $( shell go env GOARCH)
GOOS_BIN_EXT := $( if $( filter windows, $( GOOS) ) ,.exe,)
VERSION := $( shell ./scripts/version.sh)
2022-09-16 16:03:16 +00:00
# Use the highest ZSTD compression level in CI.
i f d e f C I
2022-09-16 15:36:11 +00:00
ZSTDFLAGS := -22 --ultra
2022-09-16 16:03:16 +00:00
e l s e
ZSTDFLAGS := -6
e n d i f
2022-09-16 15:36:11 +00:00
2022-12-19 12:41:36 +00:00
# Common paths to exclude from find commands, this rule is written so
# that it can be it can be used in a chain of AND statements (meaning
# you can simply write `find . $(FIND_EXCLUSIONS) -name thing-i-want`).
# Note, all find statements should be written with `.` or `./path` as
# the search path so that these exclusions match.
FIND_EXCLUSIONS = \
2023-12-01 13:13:51 +00:00
-not \( \( -path '*/.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path '*/node_modules/*' -o -path '*/out/*' -o -path './coderd/apidoc/*' -o -path '*/.next/*' -o -path '*/.terraform/*' \) -prune \)
2022-11-09 16:39:42 +00:00
# Source files used for make targets, evaluated on use.
2023-07-06 07:59:08 +00:00
GO_SRC_FILES := $( shell find . $( FIND_EXCLUSIONS) -type f -name '*.go' -not -name '*_test.go' )
2022-11-09 16:39:42 +00:00
# All the shell files in the repo, excluding ignored files.
2023-06-14 18:17:16 +00:00
SHELL_SRC_FILES := $( shell find . $( FIND_EXCLUSIONS) -type f -name '*.sh' )
2022-11-09 16:39:42 +00:00
2022-09-07 16:40:17 +00:00
# All ${OS}_${ARCH} combos we build for. Windows binaries have the .exe suffix.
OS_ARCHES := \
linux_amd64 linux_arm64 linux_armv7 \
darwin_amd64 darwin_arm64 \
windows_amd64.exe windows_arm64.exe
# Archive formats and their corresponding ${OS}_${ARCH} combos.
ARCHIVE_TAR_GZ := linux_amd64 linux_arm64 linux_armv7
ARCHIVE_ZIP := \
darwin_amd64 darwin_arm64 \
windows_amd64 windows_arm64
# All package formats we build and the ${OS}_${ARCH} combos we build them for.
PACKAGE_FORMATS := apk deb rpm
PACKAGE_OS_ARCHES := linux_amd64 linux_armv7 linux_arm64
# All architectures we build Docker images for (Linux only).
DOCKER_ARCHES := amd64 arm64 armv7
# Computed variables based on the above.
CODER_SLIM_BINARIES := $( addprefix build/coder-slim_$( VERSION) _,$( OS_ARCHES) )
CODER_FAT_BINARIES := $( addprefix build/coder_$( VERSION) _,$( OS_ARCHES) )
CODER_ALL_BINARIES := $( CODER_SLIM_BINARIES) $( CODER_FAT_BINARIES)
CODER_TAR_GZ_ARCHIVES := $( foreach os_arch, $( ARCHIVE_TAR_GZ) , build/coder_$( VERSION) _$( os_arch) .tar.gz)
CODER_ZIP_ARCHIVES := $( foreach os_arch, $( ARCHIVE_ZIP) , build/coder_$( VERSION) _$( os_arch) .zip)
CODER_ALL_ARCHIVES := $( CODER_TAR_GZ_ARCHIVES) $( CODER_ZIP_ARCHIVES)
CODER_ALL_PACKAGES := $( foreach os_arch, $( PACKAGE_OS_ARCHES) , $( addprefix build/coder_$( VERSION) _$( os_arch) .,$( PACKAGE_FORMATS) ) )
CODER_ARCH_IMAGES := $( foreach arch, $( DOCKER_ARCHES) , build/coder_$( VERSION) _linux_$( arch) .tag)
CODER_ARCH_IMAGES_PUSHED := $( addprefix push/, $( CODER_ARCH_IMAGES) )
CODER_MAIN_IMAGE := build/coder_$( VERSION) _linux.tag
CODER_SLIM_NOVERSION_BINARIES := $( addprefix build/coder-slim_,$( OS_ARCHES) )
CODER_FAT_NOVERSION_BINARIES := $( addprefix build/coder_,$( OS_ARCHES) )
CODER_ALL_NOVERSION_IMAGES := $( foreach arch, $( DOCKER_ARCHES) , build/coder_linux_$( arch) .tag) build/coder_linux.tag
CODER_ALL_NOVERSION_IMAGES_PUSHED := $( addprefix push/, $( CODER_ALL_NOVERSION_IMAGES) )
2023-01-16 17:43:37 +00:00
# If callers are only building Docker images and not the packages and archives,
# we can skip those prerequisites as they are not actually required and only
# specified to avoid concurrent write failures.
i f d e f D O C K E R _ I M A G E _ N O _ P R E R E Q U I S I T E S
CODER_ARCH_IMAGE_PREREQUISITES :=
e l s e
CODER_ARCH_IMAGE_PREREQUISITES := \
build/coder_$( VERSION) _%.apk \
build/coder_$( VERSION) _%.deb \
build/coder_$( VERSION) _%.rpm \
build/coder_$( VERSION) _%.tar.gz
e n d i f
2022-09-07 16:40:17 +00:00
clean :
2023-09-29 19:08:17 +00:00
rm -rf build/ site/build/ site/out/
mkdir -p build/ site/out/bin/
git restore site/out/
2022-09-07 16:40:17 +00:00
.PHONY : clean
build-slim : $( CODER_SLIM_BINARIES )
.PHONY : build -slim
build-fat build-full build : $( CODER_FAT_BINARIES )
.PHONY : build -fat build -full build
release : $( CODER_FAT_BINARIES ) $( CODER_ALL_ARCHIVES ) $( CODER_ALL_PACKAGES ) $( CODER_ARCH_IMAGES ) build /coder_helm_ $( VERSION ) .tgz
.PHONY : release
2022-12-15 16:36:37 +00:00
build/coder-slim_$(VERSION)_checksums.sha1 : site /out /bin /coder .sha 1
cp " $< " " $@ "
site/out/bin/coder.sha1 : $( CODER_SLIM_BINARIES )
2022-09-07 16:40:17 +00:00
pushd ./site/out/bin
openssl dgst -r -sha1 coder-* | tee coder.sha1
popd
build/coder-slim_$(VERSION).tar : build /coder -slim_ $( VERSION ) _checksums .sha 1 $( CODER_SLIM_BINARIES )
pushd ./site/out/bin
tar cf " ../../../build/ $( @F) " coder-*
popd
2022-12-21 20:59:49 +00:00
# delete the uncompressed binaries from the embedded dir
rm -f site/out/bin/coder-*
2022-12-15 16:36:37 +00:00
site/out/bin/coder.tar.zst : build /coder -slim_ $( VERSION ) .tar .zst
cp " $< " " $@ "
build/coder-slim_$(VERSION).tar.zst : build /coder -slim_ $( VERSION ) .tar
2022-09-16 15:36:11 +00:00
zstd $( ZSTDFLAGS) \
2022-09-07 16:40:17 +00:00
--force \
--long \
--no-progress \
-o " build/coder-slim_ $( VERSION) .tar.zst " \
" build/coder-slim_ $( VERSION) .tar "
# Redirect from version-less targets to the versioned ones. There is a similar
# target for slim binaries below.
#
# Called like this:
# make build/coder_linux_amd64
# make build/coder_windows_amd64.exe
$(CODER_FAT_NOVERSION_BINARIES) : build /coder_ %: build /coder_ $( VERSION ) _ %
rm -f " $@ "
ln " $< " " $@ "
# Same as above, but for slim binaries.
#
# Called like this:
# make build/coder-slim_linux_amd64
# make build/coder-slim_windows_amd64.exe
$(CODER_SLIM_NOVERSION_BINARIES) : build /coder -slim_ %: build /coder -slim_ $( VERSION ) _ %
rm -f " $@ "
ln " $< " " $@ "
# "fat" binaries always depend on the site and the compressed slim binaries.
$(CODER_FAT_BINARIES) : \
site/out/index.html \
site/out/bin/coder.sha1 \
site/out/bin/coder.tar.zst
# This is a handy block that parses the target to determine whether it's "slim"
# or "fat", which OS was specified and which architecture was specified.
#
# It populates the following variables: mode, os, arch_ext, arch, ext (without
# dot).
d e f i n e get-mode-os-arch-ext =
mode = " $$ ([[ " $@ " = build/coder-slim* ]] && echo " slim" || echo " fat")"
os = " $$ (echo $@ | cut -d_ -f3) "
arch_ext = " $$ (echo $@ | cut -d_ -f4) "
if [ [ " $$ arch_ext " = = *.* ] ] ; then
arch = " $$ (echo $$ arch_ext | cut -d. -f1) "
ext = " $$ {arch_ext#*.} "
else
arch = " $$ arch_ext "
ext = ""
fi
e n d e f
# This task handles all builds, for both "fat" and "slim" binaries. It parses
# the target name to get the metadata for the build, so it must be specified in
# this format:
# build/coder(-slim)?_${version}_${os}_${arch}(.exe)?
#
# You should probably use the non-version targets above instead if you're
# calling this manually.
$(CODER_ALL_BINARIES) : go .mod go .sum \
2022-11-09 16:39:42 +00:00
$( GO_SRC_FILES) \
2024-04-26 15:52:53 +00:00
$( shell find ./examples/templates) \
site/static/error.html
2022-09-07 16:40:17 +00:00
$( get-mode-os-arch-ext)
if [ [ " $$ os " != "windows" ] ] && [ [ " $$ ext " != "" ] ] ; then
echo "ERROR: Invalid build binary extension" 1>& 2
exit 1
fi
if [ [ " $$ os " = = "windows" ] ] && [ [ " $$ ext " != exe ] ] ; then
echo "ERROR: Windows binaries must have an .exe extension." 1>& 2
exit 1
fi
build_args = ( \
--os " $$ os " \
--arch " $$ arch " \
2022-06-18 19:47:10 +00:00
--version " $( VERSION) " \
2022-09-07 16:40:17 +00:00
--output " $@ " \
)
if [ " $$ mode " = = "slim" ] ; then
build_args += ( --slim)
fi
./scripts/build_go.sh " $$ {build_args[@]} "
if [ [ " $$ mode " = = "slim" ] ] ; then
dot_ext = ""
if [ [ " $$ ext " != "" ] ] ; then
dot_ext = " . $$ ext "
fi
cp " $@ " " ./site/out/bin/coder- $$ os- $$ arch $$ dot_ext "
fi
# This task builds all archives. It parses the target name to get the metadata
# for the build, so it must be specified in this format:
# build/coder_${version}_${os}_${arch}.${format}
#
# The following OS/arch/format combinations are supported:
# .tar.gz: linux_amd64, linux_arm64, linux_armv7
# .zip: darwin_amd64, darwin_arm64, windows_amd64, windows_arm64
#
# This depends on all fat binaries because it's difficult to do dynamic
# dependencies due to the .exe requirement on Windows. These targets are
# typically only used during release anyways.
$(CODER_ALL_ARCHIVES) : $( CODER_FAT_BINARIES )
$( get-mode-os-arch-ext)
bin_ext = ""
if [ [ " $$ os " = = "windows" ] ] ; then
bin_ext = ".exe"
fi
./scripts/archive.sh \
--format " $$ ext " \
--os " $$ os " \
--output " $@ " \
" build/coder_ $( VERSION) _ $$ {os}_ $$ {arch} $$ {bin_ext} "
# This task builds all packages. It parses the target name to get the metadata
# for the build, so it must be specified in this format:
# build/coder_${version}_linux_${arch}.${format}
#
# Supports apk, deb, rpm for all linux targets.
#
# This depends on all Linux fat binaries and archives because it's difficult to
# do dynamic dependencies due to the extensions in the filenames. These targets
# are typically only used during release anyways.
#
# Packages need to run after the archives are built, otherwise they cause tar
# errors like "file changed as we read it".
CODER_PACKAGE_DEPS := $( foreach os_arch, $( PACKAGE_OS_ARCHES) , build/coder_$( VERSION) _$( os_arch) build/coder_$( VERSION) _$( os_arch) .tar.gz)
$(CODER_ALL_PACKAGES) : $( CODER_PACKAGE_DEPS )
$( get-mode-os-arch-ext)
./scripts/package.sh \
--arch " $$ arch " \
--format " $$ ext " \
2022-09-07 01:56:51 +00:00
--version " $( VERSION) " \
2022-09-07 16:40:17 +00:00
--output " $@ " \
" build/coder_ $( VERSION) _ $$ {os}_ $$ {arch} "
2022-10-25 14:19:54 +00:00
# This task builds a Windows amd64 installer. Depends on makensis.
build/coder_$(VERSION)_windows_amd64_installer.exe : build /coder_ $( VERSION ) _windows_amd 64.exe
./scripts/build_windows_installer.sh \
--version " $( VERSION) " \
--output " $@ " \
" $< "
2022-09-07 16:40:17 +00:00
# Redirect from version-less Docker image targets to the versioned ones.
#
# Called like this:
# make build/coder_linux_amd64.tag
$(CODER_ALL_NOVERSION_IMAGES) : build /coder_ %: build /coder_ $( VERSION ) _ %
.PHONY : $( CODER_ALL_NOVERSION_IMAGES )
# Redirect from version-less push Docker image targets to the versioned ones.
#
# Called like this:
# make push/build/coder_linux_amd64.tag
$(CODER_ALL_NOVERSION_IMAGES_PUSHED) : push /build /coder_ %: push /build /coder_ $( VERSION ) _ %
.PHONY : $( CODER_ALL_NOVERSION_IMAGES_PUSHED )
# This task builds all Docker images. It parses the target name to get the
# metadata for the build, so it must be specified in this format:
# build/coder_${version}_${os}_${arch}.tag
#
# Supports linux_amd64, linux_arm64, linux_armv7.
#
# Images need to run after the archives and packages are built, otherwise they
# cause errors like "file changed as we read it".
2023-01-16 17:43:37 +00:00
$(CODER_ARCH_IMAGES) : build /coder_ $( VERSION ) _ %.tag : build /coder_ $( VERSION ) _ % $( CODER_ARCH_IMAGE_PREREQUISITES )
2022-09-07 16:40:17 +00:00
$( get-mode-os-arch-ext)
image_tag = " $$ (./scripts/image_tag.sh --arch " $$ arch" --version " $( VERSION) ")"
./scripts/build_docker.sh \
--arch " $$ arch " \
--target " $$ image_tag " \
2022-09-01 19:58:23 +00:00
--version " $( VERSION) " \
2022-09-07 16:40:17 +00:00
" build/coder_ $( VERSION) _ $$ {os}_ $$ {arch} "
echo " $$ image_tag " > " $@ "
# Multi-arch Docker image. This requires all architecture-specific images to be
# built AND pushed.
$(CODER_MAIN_IMAGE) : $( CODER_ARCH_IMAGES_PUSHED )
image_tag = " $$ (./scripts/image_tag.sh --version " $( VERSION) ")"
./scripts/build_docker_multiarch.sh \
--target " $$ image_tag " \
2022-09-07 01:56:51 +00:00
--version " $( VERSION) " \
2022-09-07 16:40:17 +00:00
$( foreach img, $^, " $$ (cat " $( img:push/%= %) ")" )
echo " $$ image_tag " > " $@ "
# Push a Docker image.
$(CODER_ARCH_IMAGES_PUSHED) : push /%: %
image_tag = " $$ (cat " $<")"
docker push " $$ image_tag "
.PHONY : $( CODER_ARCH_IMAGES_PUSHED )
# Push the multi-arch Docker manifest.
push/$(CODER_MAIN_IMAGE) : $( CODER_MAIN_IMAGE )
image_tag = " $$ (cat " $<")"
docker manifest push " $$ image_tag "
.PHONY : push /$( CODER_MAIN_IMAGE )
2023-08-16 12:26:38 +00:00
# Helm charts that are available
charts = coder provisioner
2022-09-07 16:40:17 +00:00
# Shortcut for Helm chart package.
2023-08-16 12:26:38 +00:00
$(foreach chart,$(charts),build/$(chart)_helm.tgz) : build /%_helm .tgz : build /%_helm_ $( VERSION ) .tgz
2022-09-07 16:40:17 +00:00
rm -f " $@ "
ln " $< " " $@ "
# Helm chart package.
2023-08-16 12:26:38 +00:00
$(foreach chart,$(charts),build/$(chart)_helm_$(VERSION).tgz) : build /%_helm_ $( VERSION ) .tgz :
2022-09-07 16:40:17 +00:00
./scripts/helm.sh \
2022-09-07 01:56:51 +00:00
--version " $( VERSION) " \
2023-08-16 12:26:38 +00:00
--chart $* \
2022-09-07 16:40:17 +00:00
--output " $@ "
2022-09-01 19:58:23 +00:00
2022-12-19 12:41:36 +00:00
site/out/index.html : site /package .json $( shell find ./site $ ( FIND_EXCLUSIONS ) -type f \( -name '*.ts ' -o -name '*.tsx ' \) )
2022-09-07 16:40:17 +00:00
cd site
2024-02-27 17:45:57 +00:00
# prevents this directory from getting to big, and causing "too much data" errors
rm -rf out/assets/
2023-08-02 18:28:16 +00:00
../scripts/pnpm_install.sh
pnpm build
2022-01-05 15:20:56 +00:00
2023-07-19 16:57:57 +00:00
offlinedocs/out/index.html : $( shell find ./offlinedocs $ ( FIND_EXCLUSIONS ) -type f ) $( shell find ./docs $ ( FIND_EXCLUSIONS ) -type f | sed 's : :\\ :g ')
cd offlinedocs
2023-08-02 18:28:16 +00:00
../scripts/pnpm_install.sh
pnpm export
2023-07-19 16:57:57 +00:00
build/coder_docs_$(VERSION).tgz : offlinedocs /out /index .html
tar -czf " $@ " -C offlinedocs/out .
2022-09-07 16:40:17 +00:00
install : build /coder_ $( VERSION ) _ $( GOOS ) _ $( GOARCH ) $( GOOS_BIN_EXT )
install_dir = " $$ (go env GOPATH)/bin "
output_file = " $$ {install_dir}/coder $( GOOS_BIN_EXT) "
mkdir -p " $$ install_dir "
cp " $< " " $$ output_file "
.PHONY : install
2024-04-05 17:45:32 +00:00
BOLD := $( shell tput bold 2>/dev/null)
GREEN := $( shell tput setaf 2 2>/dev/null)
RESET := $( shell tput sgr0 2>/dev/null)
2024-03-05 23:31:22 +00:00
fmt : fmt /eslint fmt /prettier fmt /terraform fmt /shfmt fmt /go
2022-09-07 16:40:17 +00:00
.PHONY : fmt
2022-01-05 15:20:56 +00:00
2023-02-19 00:32:09 +00:00
fmt/go :
2024-03-05 23:31:22 +00:00
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/go $( RESET) "
2023-02-19 00:32:09 +00:00
# VS Code users should check out
# https://github.com/mvdan/gofumpt#visual-studio-code
go run mvdan.cc/gofumpt@v0.4.0 -w -l .
.PHONY : fmt /go
2024-03-05 23:31:22 +00:00
fmt/eslint :
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/eslint $( RESET) "
cd site
pnpm run lint:fix
.PHONY : fmt /eslint
2022-01-04 02:54:27 +00:00
fmt/prettier :
2024-03-05 23:31:22 +00:00
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/prettier $( RESET) "
2022-06-18 19:47:10 +00:00
cd site
2022-01-04 02:54:27 +00:00
# Avoid writing files in CI to reduce file write activity
i f d e f C I
2023-08-02 18:28:16 +00:00
pnpm run format:check
2022-01-04 02:54:27 +00:00
e l s e
2024-03-05 23:31:22 +00:00
pnpm run format
2022-01-04 02:54:27 +00:00
e n d i f
.PHONY : fmt /prettier
2022-04-11 21:06:15 +00:00
fmt/terraform : $( wildcard *.tf )
2024-03-05 23:31:22 +00:00
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/terraform $( RESET) "
2022-04-11 21:06:15 +00:00
terraform fmt -recursive
2022-05-02 19:04:45 +00:00
.PHONY : fmt /terraform
2022-04-11 21:06:15 +00:00
2022-11-09 16:39:42 +00:00
fmt/shfmt : $( SHELL_SRC_FILES )
2024-03-05 23:31:22 +00:00
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/shfmt $( RESET) "
2022-05-27 17:15:19 +00:00
# Only do diff check in CI, errors on diff.
i f d e f C I
2022-11-09 16:39:42 +00:00
shfmt -d $( SHELL_SRC_FILES)
2022-05-27 17:15:19 +00:00
e l s e
2022-11-09 16:39:42 +00:00
shfmt -w $( SHELL_SRC_FILES)
2022-05-27 17:15:19 +00:00
e n d i f
2022-06-18 19:47:10 +00:00
.PHONY : fmt /shfmt
2022-05-27 17:15:19 +00:00
2024-03-14 14:49:44 +00:00
lint : lint /shellcheck lint /go lint /ts lint /examples lint /helm lint /site -icons
2022-06-18 19:47:10 +00:00
.PHONY : lint
2022-05-27 17:15:19 +00:00
2023-07-23 21:27:11 +00:00
lint/site-icons :
./scripts/check_site_icons.sh
.PHONY : lint /site -icons
2023-06-12 17:09:54 +00:00
lint/ts :
cd site
2023-08-02 18:28:16 +00:00
pnpm i && pnpm lint
2023-06-12 17:09:54 +00:00
.PHONY : lint /ts
2022-05-27 17:15:19 +00:00
lint/go :
2022-08-19 17:49:08 +00:00
./scripts/check_enterprise_imports.sh
2023-12-12 10:02:32 +00:00
linter_ver = $( shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/Dockerfile | cut -d '=' -f 2)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$$ linter_ver
2022-03-28 20:21:00 +00:00
golangci-lint run
2022-05-27 17:15:19 +00:00
.PHONY : lint /go
2024-03-14 14:49:44 +00:00
lint/examples :
go run ./scripts/examplegen/main.go -lint
.PHONY : lint /examples
2022-05-27 17:15:19 +00:00
# Use shfmt to determine the shell files, takes editorconfig into consideration.
2022-11-09 16:39:42 +00:00
lint/shellcheck : $( SHELL_SRC_FILES )
2022-09-07 16:40:17 +00:00
echo "--- shellcheck"
2022-11-09 16:39:42 +00:00
shellcheck --external-sources $( SHELL_SRC_FILES)
2022-06-18 19:47:10 +00:00
.PHONY : lint /shellcheck
2022-03-28 20:21:00 +00:00
2023-06-12 17:09:54 +00:00
lint/helm :
cd helm
make lint
.PHONY : lint /helm
2023-07-06 07:59:08 +00:00
# All files generated by the database should be added here, and this can be used
# as a target for jobs that need to run after the database is generated.
DB_GEN_FILES := \
coderd/database/querier.go \
coderd/database/unique_constraint.go \
2023-10-30 17:42:20 +00:00
coderd/database/dbmem/dbmem.go \
2023-07-06 07:59:08 +00:00
coderd/database/dbmetrics/dbmetrics.go \
coderd/database/dbauthz/dbauthz.go \
coderd/database/dbmock/dbmock.go
2022-09-07 16:40:17 +00:00
# all gen targets should be added here and to gen/mark-fresh
gen : \
2023-10-30 08:14:45 +00:00
tailnet/proto/tailnet.pb.go \
agent/proto/agent.pb.go \
2022-09-07 16:40:17 +00:00
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
2023-08-25 06:10:15 +00:00
coderd/database/dump.sql \
$( DB_GEN_FILES) \
2022-11-30 16:39:51 +00:00
site/src/api/typesGenerated.ts \
2023-04-11 13:57:23 +00:00
coderd/rbac/object_gen.go \
2022-12-19 17:43:46 +00:00
docs/admin/prometheus.md \
2023-02-23 17:07:57 +00:00
docs/cli.md \
2023-01-26 23:12:12 +00:00
docs/admin/audit-logs.md \
2023-01-03 13:11:13 +00:00
coderd/apidoc/swagger.json \
.prettierignore.include \
.prettierignore \
site/.prettierrc.yaml \
site/.prettierignore \
2023-08-18 08:50:43 +00:00
site/.eslintignore \
2023-09-04 17:15:29 +00:00
site/e2e/provisionerGenerated.ts \
2023-10-06 19:46:37 +00:00
site/src/theme/icons.json \
2024-01-22 07:07:50 +00:00
examples/examples.gen.json \
2024-01-23 09:17:56 +00:00
tailnet/tailnettest/coordinatormock.go \
tailnet/tailnettest/coordinateemock.go \
tailnet/tailnettest/multiagentmock.go
2022-09-07 16:40:17 +00:00
.PHONY : gen
# Mark all generated files as fresh so make thinks they're up-to-date. This is
# used during releases so we don't run generation scripts.
gen/mark-fresh :
2023-01-03 13:11:13 +00:00
files = " \
2023-10-30 08:14:45 +00:00
tailnet/proto/tailnet.pb.go \
agent/proto/agent.pb.go \
2023-01-03 13:11:13 +00:00
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
2023-08-25 06:10:15 +00:00
coderd/database/dump.sql \
$( DB_GEN_FILES) \
2023-01-03 13:11:13 +00:00
site/src/api/typesGenerated.ts \
2023-04-11 13:57:23 +00:00
coderd/rbac/object_gen.go \
2023-01-03 13:11:13 +00:00
docs/admin/prometheus.md \
2023-02-23 17:07:57 +00:00
docs/cli.md \
2023-01-26 23:12:12 +00:00
docs/admin/audit-logs.md \
2023-01-03 13:11:13 +00:00
coderd/apidoc/swagger.json \
.prettierignore.include \
.prettierignore \
site/.prettierrc.yaml \
site/.prettierignore \
site/.eslintignore \
2023-08-18 08:50:43 +00:00
site/e2e/provisionerGenerated.ts \
2023-10-06 19:46:37 +00:00
site/src/theme/icons.json \
2023-09-04 17:15:29 +00:00
examples/examples.gen.json \
2024-01-22 07:07:50 +00:00
tailnet/tailnettest/coordinatormock.go \
2024-01-23 09:17:56 +00:00
tailnet/tailnettest/coordinateemock.go \
tailnet/tailnettest/multiagentmock.go \
2023-01-03 13:11:13 +00:00
"
2022-09-07 16:40:17 +00:00
for file in $$ files; do
echo " $$ file "
if [ ! -f " $$ file " ] ; then
echo " File ' $$ file' does not exist "
exit 1
fi
# touch sets the mtime of the file to the current time
touch $$ file
done
.PHONY : gen /mark -fresh
# Runs migrations to output a dump of the database schema after migrations are
# applied.
coderd/database/dump.sql : coderd /database /gen /dump /main .go $( wildcard coderd /database /migrations /*.sql )
2022-09-22 22:30:32 +00:00
go run ./coderd/database/gen/dump/main.go
2022-09-07 16:40:17 +00:00
# Generates Go code for querying the database.
2023-10-17 20:41:35 +00:00
# coderd/database/queries.sql.go
# coderd/database/models.go
2023-06-20 16:24:33 +00:00
coderd/database/querier.go : coderd /database /sqlc .yaml coderd /database /dump .sql $( wildcard coderd /database /queries /*.sql )
2022-09-07 16:40:17 +00:00
./coderd/database/generate.sh
2023-06-13 18:57:43 +00:00
coderd/database/dbmock/dbmock.go : coderd /database /db .go coderd /database /querier .go
2023-05-23 08:06:33 +00:00
go generate ./coderd/database/dbmock/
2024-01-23 09:17:56 +00:00
tailnet/tailnettest/coordinatormock.go tailnet/tailnettest/multiagentmock.go tailnet/tailnettest/coordinateemock.go : tailnet /coordinator .go tailnet /multiagent .go
2024-01-22 07:07:50 +00:00
go generate ./tailnet/tailnettest/
2023-10-30 08:14:45 +00:00
tailnet/proto/tailnet.pb.go : tailnet /proto /tailnet .proto
protoc \
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./tailnet/proto/tailnet.proto
agent/proto/agent.pb.go : agent /proto /agent .proto
protoc \
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./agent/proto/agent.proto
2022-09-07 16:40:17 +00:00
provisionersdk/proto/provisioner.pb.go : provisionersdk /proto /provisioner .proto
2022-01-29 23:52:14 +00:00
protoc \
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
2022-09-07 16:40:17 +00:00
./provisionersdk/proto/provisioner.proto
2022-01-29 23:52:14 +00:00
2022-09-07 16:40:17 +00:00
provisionerd/proto/provisionerd.pb.go : provisionerd /proto /provisionerd .proto
2022-01-29 23:52:14 +00:00
protoc \
2022-01-08 17:24:02 +00:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
2022-09-07 16:40:17 +00:00
./provisionerd/proto/provisionerd.proto
2022-05-02 18:23:13 +00:00
2023-10-17 20:41:35 +00:00
site/src/api/typesGenerated.ts : $( wildcard scripts /apitypings /*) $( shell find ./codersdk $ ( FIND_EXCLUSIONS ) -type f -name '*.go ')
go run ./scripts/apitypings/ > $@
2024-03-08 12:33:28 +00:00
./scripts/pnpm_install.sh
2024-03-05 23:31:22 +00:00
pnpm exec prettier --write " $@ "
2022-03-28 19:14:40 +00:00
2023-09-30 19:30:01 +00:00
site/e2e/provisionerGenerated.ts : provisionerd /proto /provisionerd .pb .go provisionersdk /proto /provisioner .pb .go
2023-08-18 08:50:43 +00:00
cd site
../scripts/pnpm_install.sh
pnpm run gen:provisioner
2023-10-17 20:41:35 +00:00
site/src/theme/icons.json : $( wildcard scripts /gensite /*) $( wildcard site /static /icon /*)
go run ./scripts/gensite/ -icons " $@ "
2024-03-08 12:33:28 +00:00
./scripts/pnpm_install.sh
2024-03-05 23:31:22 +00:00
pnpm exec prettier --write " $@ "
2023-10-06 19:46:37 +00:00
2023-09-04 17:15:29 +00:00
examples/examples.gen.json : scripts /examplegen /main .go examples /examples .go $( shell find ./examples /templates )
go run ./scripts/examplegen/main.go > examples/examples.gen.json
2023-04-11 13:57:23 +00:00
coderd/rbac/object_gen.go : scripts /rbacgen /main .go coderd /rbac /object .go
go run scripts/rbacgen/main.go ./coderd/rbac > coderd/rbac/object_gen.go
2022-11-30 16:39:51 +00:00
docs/admin/prometheus.md : scripts /metricsdocgen /main .go scripts /metricsdocgen /metrics
go run scripts/metricsdocgen/main.go
2024-03-08 12:33:28 +00:00
./scripts/pnpm_install.sh
2024-03-05 23:31:22 +00:00
pnpm exec prettier --write ./docs/admin/prometheus.md
2022-11-30 16:39:51 +00:00
2023-09-04 17:15:29 +00:00
docs/cli.md : scripts /clidocgen /main .go examples /examples .gen .json $( GO_SRC_FILES )
2023-09-07 21:28:22 +00:00
CI = true BASE_PATH = "." go run ./scripts/clidocgen
2024-03-08 12:33:28 +00:00
./scripts/pnpm_install.sh
2024-03-05 23:31:22 +00:00
pnpm exec prettier --write ./docs/cli.md ./docs/cli/*.md ./docs/manifest.json
2023-01-27 18:10:40 +00:00
2023-12-15 11:49:19 +00:00
docs/admin/audit-logs.md : coderd /database /querier .go scripts /auditdocgen /main .go enterprise /audit /table .go coderd /rbac /object_gen .go
2023-01-26 23:12:12 +00:00
go run scripts/auditdocgen/main.go
2024-03-08 12:33:28 +00:00
./scripts/pnpm_install.sh
2024-03-05 23:31:22 +00:00
pnpm exec prettier --write ./docs/admin/audit-logs.md
2023-01-26 23:12:12 +00:00
2023-07-06 07:59:08 +00:00
coderd/apidoc/swagger.json : $( shell find ./scripts /apidocgen $ ( FIND_EXCLUSIONS ) -type f ) $( wildcard coderd /*.go ) $( wildcard enterprise /coderd /*.go ) $( wildcard codersdk /*.go ) $( wildcard enterprise /wsproxy /wsproxysdk /*.go ) $( DB_GEN_FILES ) .swaggo docs /manifest .json coderd /rbac /object_gen .go
2022-12-19 17:43:46 +00:00
./scripts/apidocgen/generate.sh
2024-03-08 12:33:28 +00:00
./scripts/pnpm_install.sh
2024-03-05 23:31:22 +00:00
pnpm exec prettier --write ./docs/api ./docs/manifest.json ./coderd/apidoc/swagger.json
2022-12-19 17:43:46 +00:00
2023-11-28 18:37:20 +00:00
update-golden-files : \
cli/testdata/.gen-golden \
helm/coder/tests/testdata/.gen-golden \
helm/provisioner/tests/testdata/.gen-golden \
scripts/ci-report/testdata/.gen-golden \
enterprise/cli/testdata/.gen-golden \
enterprise/tailnet/testdata/.gen-golden \
2023-12-06 11:04:28 +00:00
tailnet/testdata/.gen-golden \
2023-11-28 18:37:20 +00:00
coderd/.gen-golden \
provisioner/terraform/testdata/.gen-golden
2022-11-04 17:48:36 +00:00
.PHONY : update -golden -files
2023-07-06 07:59:08 +00:00
cli/testdata/.gen-golden : $( wildcard cli /testdata /*.golden ) $( wildcard cli /*.tpl ) $( GO_SRC_FILES ) $( wildcard cli /*_test .go )
2024-04-01 14:19:26 +00:00
go test ./cli -run= "Test(CommandHelp|ServerYAML|ErrorExamples)" -update
2022-11-04 17:48:36 +00:00
touch " $@ "
2023-07-06 07:59:08 +00:00
enterprise/cli/testdata/.gen-golden : $( wildcard enterprise /cli /testdata /*.golden ) $( wildcard cli /*.tpl ) $( GO_SRC_FILES ) $( wildcard enterprise /cli /*_test .go )
2023-06-09 16:35:20 +00:00
go test ./enterprise/cli -run= "TestEnterpriseCommandHelp" -update
touch " $@ "
2023-12-06 11:04:28 +00:00
tailnet/testdata/.gen-golden : $( wildcard tailnet /testdata /*.golden .html ) $( GO_SRC_FILES ) $( wildcard tailnet /*_test .go )
go test ./tailnet -run= "TestDebugTemplate" -update
touch " $@ "
2023-11-28 18:37:20 +00:00
enterprise/tailnet/testdata/.gen-golden : $( wildcard enterprise /tailnet /testdata /*.golden .html ) $( GO_SRC_FILES ) $( wildcard enterprise /tailnet /*_test .go )
go test ./enterprise/tailnet -run= "TestDebugTemplate" -update
touch " $@ "
2023-08-10 09:59:43 +00:00
helm/coder/tests/testdata/.gen-golden : $( wildcard helm /coder /tests /testdata /*.yaml ) $( wildcard helm /coder /tests /testdata /*.golden ) $( GO_SRC_FILES ) $( wildcard helm /coder /tests /*_test .go )
go test ./helm/coder/tests -run= TestUpdateGoldenFiles -update
touch " $@ "
helm/provisioner/tests/testdata/.gen-golden : $( wildcard helm /provisioner /tests /testdata /*.yaml ) $( wildcard helm /provisioner /tests /testdata /*.golden ) $( GO_SRC_FILES ) $( wildcard helm /provisioner /tests /*_test .go )
go test ./helm/provisioner/tests -run= TestUpdateGoldenFiles -update
2023-03-13 13:48:44 +00:00
touch " $@ "
2023-08-24 10:36:40 +00:00
coderd/.gen-golden : $( wildcard coderd /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard coderd /*_test .go )
go test ./coderd -run= " Test.*Golden $$ " -update
touch " $@ "
2023-09-11 07:37:14 +00:00
provisioner/terraform/testdata/.gen-golden : $( wildcard provisioner /terraform /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard provisioner /terraform /*_test .go )
go test ./provisioner/terraform -run= " Test.*Golden $$ " -update
touch " $@ "
2023-04-03 11:07:25 +00:00
scripts/ci-report/testdata/.gen-golden : $( wildcard scripts /ci -report /testdata /*) $( wildcard scripts /ci -report /*.go )
go test ./scripts/ci-report -run= TestOutputMatchesGoldenFile -update
touch " $@ "
2023-01-03 13:11:13 +00:00
# Generate a prettierrc for the site package that uses relative paths for
# overrides. This allows us to share the same prettier config between the
# site and the root of the repo.
site/.prettierrc.yaml : .prettierrc .yaml
. ./scripts/lib.sh
dependencies yq
echo " # Code generated by Makefile (../ $<). DO NOT EDIT. " > " $@ "
echo "" >> " $@ "
# Replace all listed override files with relative paths inside site/.
# - ./ -> ../
# - ./site -> ./
yq \
2023-09-04 17:15:29 +00:00
'.overrides[].files |= map(. | sub("^./"; "") | sub("^"; "../") | sub("../site/"; "./") | sub("../!"; "!../"))' \
2023-01-03 13:11:13 +00:00
" $< " >> " $@ "
# Combine .gitignore with .prettierignore.include to generate .prettierignore.
.prettierignore : .gitignore .prettierignore .include
echo " # Code generated by Makefile ( $^). DO NOT EDIT. " > " $@ "
echo "" >> " $@ "
for f in $^; do
echo " # $$ {f}: " >> " $@ "
cat " $$ f " >> " $@ "
done
# Generate ignore files based on gitignore into the site directory. We turn all
# rules into relative paths for the `site/` directory (where applicable),
# following the pattern format defined by git:
# https://git-scm.com/docs/gitignore#_pattern_format
#
# This is done for compatibility reasons, see:
# https://github.com/prettier/prettier/issues/8048
# https://github.com/prettier/prettier/issues/8506
# https://github.com/prettier/prettier/issues/8679
site/.eslintignore site/.prettierignore : .prettierignore Makefile
rm -f " $@ "
touch " $@ "
# Skip generated by header, inherit `.prettierignore` header as-is.
while read -r rule; do
# Remove leading ! if present to simplify rule, added back at the end.
tmp = " $$ {rule#!} "
ignore = " $$ {rule% " $$ tmp"}"
rule = " $$ tmp "
case " $$ rule " in
# Comments or empty lines (include).
\# *| '' ) ; ;
# Generic rules (include).
\* \* *) ; ;
# Site prefixed rules (include).
site/*) rule = " $$ {rule#site/} " ; ;
./site/*) rule = " $$ {rule#./site/} " ; ;
# Rules that are non-generic and don't start with site (rewrite).
/*) rule = .." $$ rule " ; ;
*/?*) rule = ../" $$ rule " ; ;
*) ; ;
esac
echo " $$ {ignore} $$ {rule} " >> " $@ "
done < " $< "
2023-07-07 11:16:16 +00:00
test :
gotestsum --format standard-quiet -- -v -short -count= 1 ./...
2022-06-18 19:47:10 +00:00
.PHONY : test
2022-05-20 23:39:51 +00:00
2023-12-19 20:31:55 +00:00
# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a
# dependency for any sqlc-cloud related targets.
sqlc-cloud-is-setup :
if [ [ " $( SQLC_AUTH_TOKEN) " = = "" ] ] ; then
echo "ERROR: 'SQLC_AUTH_TOKEN' must be set to auth with sqlc cloud before running verify." 1>& 2
exit 1
fi
.PHONY : sqlc -cloud -is -setup
sqlc-push : sqlc -cloud -is -setup test -postgres -docker
echo "--- sqlc push"
SQLC_DATABASE_URL = " postgresql://postgres:postgres@localhost:5432/ $( shell go run scripts/migrate-ci/main.go) " \
sqlc push -f coderd/database/sqlc.yaml && echo "Passed sqlc push"
.PHONY : sqlc -push
sqlc-verify : sqlc -cloud -is -setup test -postgres -docker
echo "--- sqlc verify"
SQLC_DATABASE_URL = " postgresql://postgres:postgres@localhost:5432/ $( shell go run scripts/migrate-ci/main.go) " \
sqlc verify -f coderd/database/sqlc.yaml && echo "Passed sqlc verify"
.PHONY : sqlc -verify
2023-12-12 21:53:26 +00:00
sqlc-vet : test -postgres -docker
echo "--- sqlc vet"
SQLC_DATABASE_URL = " postgresql://postgres:postgres@localhost:5432/ $( shell go run scripts/migrate-ci/main.go) " \
sqlc vet -f coderd/database/sqlc.yaml && echo "Passed sqlc vet"
2023-12-12 22:55:13 +00:00
.PHONY : sqlc -vet
2023-12-12 21:53:26 +00:00
2022-07-22 09:47:03 +00:00
# When updating -timeout for this test, keep in sync with
# test-go-postgres (.github/workflows/coder.yaml).
2023-06-09 21:46:44 +00:00
# Do add coverage flags so that test caching works.
2023-07-07 11:16:16 +00:00
test-postgres : test -postgres -docker
2022-11-13 20:23:23 +00:00
# The postgres test is prone to failure, so we limit parallelism for
# more consistent execution.
2022-12-07 14:04:39 +00:00
DB = ci DB_FROM = $( shell go run scripts/migrate-ci/main.go) gotestsum \
--junitfile= "gotests.xml" \
2023-04-03 11:07:25 +00:00
--jsonfile= "gotests.json" \
2022-12-07 14:04:39 +00:00
--packages= "./..." -- \
2023-06-09 21:46:44 +00:00
-timeout= 20m \
2023-07-07 11:16:16 +00:00
-failfast \
-count= 1
2022-06-18 19:47:10 +00:00
.PHONY : test -postgres
2022-05-20 23:39:51 +00:00
2024-04-23 11:43:14 +00:00
test-migrations : test -postgres -docker
echo "--- test migrations"
2024-04-24 07:31:01 +00:00
set -euo pipefail
2024-04-23 11:43:14 +00:00
COMMIT_FROM = $( shell git rev-parse --short HEAD)
COMMIT_TO = $( shell git rev-parse --short main)
2024-04-24 07:31:01 +00:00
echo " DROP DATABASE IF EXISTS migrate_test_ $$ {COMMIT_FROM}; CREATE DATABASE migrate_test_ $$ {COMMIT_FROM}; " | psql 'postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable'
go run ./scripts/migrate-test/main.go --from= " $$ COMMIT_FROM " --to= " $$ COMMIT_TO " --postgres-url= " postgresql://postgres:postgres@localhost:5432/migrate_test_ $$ {COMMIT_FROM}?sslmode=disable "
2024-04-23 11:43:14 +00:00
2024-03-21 14:53:16 +00:00
# NOTE: we set --memory to the same size as a GitHub runner.
2022-05-20 23:39:51 +00:00
test-postgres-docker :
2022-06-27 17:07:39 +00:00
docker rm -f test-postgres-docker || true
2022-05-20 23:39:51 +00:00
docker run \
--env POSTGRES_PASSWORD = postgres \
--env POSTGRES_USER = postgres \
--env POSTGRES_DB = postgres \
--env PGDATA = /tmp \
2022-06-17 19:57:38 +00:00
--tmpfs /tmp \
2022-05-20 23:39:51 +00:00
--publish 5432:5432 \
--name test-postgres-docker \
2022-06-17 19:57:38 +00:00
--restart no \
2022-05-20 23:39:51 +00:00
--detach \
2024-03-21 14:53:16 +00:00
--memory 16GB \
2023-06-09 13:39:55 +00:00
gcr.io/coder-dev-1/postgres:13 \
2022-05-20 23:39:51 +00:00
-c shared_buffers = 1GB \
2023-05-14 20:32:44 +00:00
-c work_mem = 1GB \
-c effective_cache_size = 1GB \
2022-06-17 19:57:38 +00:00
-c max_connections = 1000 \
-c fsync = off \
-c synchronous_commit = off \
2023-02-03 18:58:31 +00:00
-c full_page_writes = off \
-c log_statement = all
2022-06-27 17:07:39 +00:00
while ! pg_isready -h 127.0.0.1
do
echo " $( date) - waiting for database to start "
sleep 0.5
done
2022-06-18 19:47:10 +00:00
.PHONY : test -postgres -docker
2022-05-20 23:39:51 +00:00
2023-07-07 10:15:50 +00:00
# Make sure to keep this in sync with test-go-race from .github/workflows/ci.yaml.
2023-07-07 11:16:16 +00:00
test-race :
gotestsum --junitfile= "gotests.xml" -- -race -count= 1 ./...
2023-07-07 10:15:50 +00:00
.PHONY : test -race
2023-07-07 11:16:16 +00:00
# Note: we used to add this to the test target, but it's not necessary and we can
# achieve the desired result by specifying -count=1 in the go test invocation
# instead. Keeping it here for convenience.
2022-05-20 23:39:51 +00:00
test-clean :
go clean -testcache
2022-06-18 19:47:10 +00:00
.PHONY : test -clean