2022-09-08 02:40:17 +10: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 14:04:45 -05:00
2022-06-18 14:47:10 -05:00
# Use a single bash shell for each job, and immediately exit on failure
SHELL := bash
2022-09-08 02:40:17 +10:00
.SHELLFLAGS := -ceu
2022-06-18 14:47:10 -05: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-08 02:40:17 +10: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.
ifndef VERBOSE
.SILENT :
endif
2022-02-10 20:32:00 -08:00
2022-09-08 02:40:17 +10:00
# Create the output directories if they do not exist.
$( shell mkdir -p build site /out /bin )
2022-05-02 14:04:45 -05:00
2022-09-08 02:40:17 +10:00
GOOS := $( shell go env GOOS)
GOARCH := $( shell go env GOARCH)
GOOS_BIN_EXT := $(if $( filter windows, $( GOOS)) ,.exe,)
VERSION := $( shell ./scripts/version.sh)
2025-06-11 23:06:31 +10:00
POSTGRES_VERSION ?= 17
POSTGRES_IMAGE ?= us-docker.pkg.dev/coder-v2-images-public/public/postgres:$( POSTGRES_VERSION)
2022-09-08 02:40:17 +10:00
2022-09-17 02:03:16 +10:00
# Use the highest ZSTD compression level in CI.
ifdef CI
2022-09-16 18:36:11 +03:00
ZSTDFLAGS := -22 --ultra
2022-09-17 02:03:16 +10:00
else
ZSTDFLAGS := -6
endif
2022-09-16 18:36:11 +03:00
2022-12-19 14:41:36 +02: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 15:13:51 +02: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 18:39:42 +02:00
# Source files used for make targets, evaluated on use.
2023-07-06 10:59:08 +03:00
GO_SRC_FILES := $( shell find . $( FIND_EXCLUSIONS) -type f -name '*.go' -not -name '*_test.go' )
2025-03-24 13:41:45 +02:00
# Same as GO_SRC_FILES but excluding certain files that have problematic
# Makefile dependencies (e.g. pnpm).
MOST_GO_SRC_FILES := $( shell \
find . \
$( FIND_EXCLUSIONS) \
-type f \
-name '*.go' \
-not -name '*_test.go' \
-not -wholename './agent/agentcontainers/dcspec/dcspec_gen.go' \
)
2022-11-09 18:39:42 +02:00
# All the shell files in the repo, excluding ignored files.
2023-06-14 13:17:16 -05:00
SHELL_SRC_FILES := $( shell find . $( FIND_EXCLUSIONS) -type f -name '*.sh' )
2022-11-09 18:39:42 +02:00
2024-05-10 16:35:59 +02:00
# Ensure we don't use the user's git configs which might cause side-effects
GIT_FLAGS = GIT_CONFIG_GLOBAL = /dev/null GIT_CONFIG_SYSTEM = /dev/null
2022-09-08 02:40:17 +10: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
2024-11-20 14:13:03 +11:00
# All ${OS}_${ARCH} combos we build the desktop dylib for.
DYLIB_ARCHES := darwin_amd64 darwin_arm64
2022-09-08 02:40:17 +10:00
# Computed variables based on the above.
CODER_SLIM_BINARIES := $( addprefix build/coder-slim_$( VERSION) _,$( OS_ARCHES))
2024-11-20 14:13:03 +11:00
CODER_DYLIBS := $( foreach os_arch, $( DYLIB_ARCHES) , build/coder-vpn_$( VERSION) _$( os_arch) .dylib)
2022-09-08 02:40:17 +10:00
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 11:43:37 -06: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.
ifdef DOCKER_IMAGE_NO_PREREQUISITES
CODER_ARCH_IMAGE_PREREQUISITES :=
else
CODER_ARCH_IMAGE_PREREQUISITES := \
build/coder_$( VERSION) _%.apk \
build/coder_$( VERSION) _%.deb \
build/coder_$( VERSION) _%.rpm \
build/coder_$( VERSION) _%.tar.gz
endif
2022-09-08 02:40:17 +10:00
clean :
2023-09-29 13:08:17 -06:00
rm -rf build/ site/build/ site/out/
2025-02-24 10:43:03 -07:00
mkdir -p build/
2023-09-29 13:08:17 -06:00
git restore site/out/
2022-09-08 02:40:17 +10: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 18:36:37 +02:00
build/coder-slim_$(VERSION)_checksums.sha1 : site /out /bin /coder .sha 1
cp " $<" " $@ "
site/out/bin/coder.sha1 : $( CODER_SLIM_BINARIES )
2022-09-08 02:40:17 +10: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 22:59:49 +02:00
# delete the uncompressed binaries from the embedded dir
rm -f site/out/bin/coder-*
2022-12-15 18:36:37 +02: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 18:36:11 +03:00
zstd $( ZSTDFLAGS) \
2022-09-08 02:40:17 +10: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 .sha 1 \
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).
define 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
endef
# 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 18:39:42 +02:00
$( GO_SRC_FILES ) \
2024-04-26 11:52:53 -04:00
$( shell find ./examples /templates ) \
site /static /error .html
2022-09-08 02:40:17 +10: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 14:47:10 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
--output " $@ " \
)
if [ " $$ mode" == "slim" ] ; then
build_args +=( --slim)
fi
2022-06-18 14:47:10 -05:00
2022-09-08 02:40:17 +10:00
./scripts/build_go.sh " $$ {build_args[@]}"
2022-09-01 14:58:23 -05:00
2022-09-08 02:40:17 +10:00
if [[ " $$ mode" == "slim" ]] ; then
dot_ext = ""
if [[ " $$ ext" != "" ]] ; then
dot_ext = ". $$ ext"
fi
2022-06-18 14:47:10 -05:00
2022-09-08 02:40:17 +10:00
cp " $@ " "./site/out/bin/coder- $$ os- $$ arch $$ dot_ext"
2025-07-09 11:53:27 +02:00
if [[ " $$ {CODER_SIGN_GPG:-0}" == "1" ]] ; then
cp " $@ .asc" "./site/out/bin/coder- $$ os- $$ arch $$ dot_ext.asc"
fi
2022-09-08 02:40:17 +10:00
fi
2024-11-20 14:13:03 +11:00
# This task builds Coder Desktop dylibs
2025-03-24 13:41:45 +02:00
$(CODER_DYLIBS) : go .mod go .sum $( MOST_GO_SRC_FILES )
2024-11-20 14:13:03 +11:00
@if [ " $( shell uname) " = "Darwin" ] ; then
$( get-mode-os-arch-ext)
./scripts/build_go.sh \
--os " $$ os" \
--arch " $$ arch" \
--version " $( VERSION) " \
--output " $@ " \
--dylib
else
echo "ERROR: Can't build dylib on non-Darwin OS" 1>& 2
exit 1
fi
# This task builds both dylibs
build/coder-dylib : $( CODER_DYLIBS )
2025-01-03 12:27:26 -08:00
.PHONY : build /coder -dylib
2024-11-20 14:13:03 +11:00
2022-09-08 02:40:17 +10:00
# 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-06-18 14:47:10 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
--output " $@ " \
"build/coder_ $( VERSION) _ $$ {os}_ $$ {arch}"
2022-06-18 14:47:10 -05:00
2022-10-26 00:19:54 +10: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-08 02:40:17 +10: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 11:43:37 -06:00
$(CODER_ARCH_IMAGES) : build /coder_ $( VERSION ) _ %.tag : build /coder_ $( VERSION ) _ % $( CODER_ARCH_IMAGE_PREREQUISITES )
2022-09-08 02:40:17 +10: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-06-18 14:47:10 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
"build/coder_ $( VERSION) _ $$ {os}_ $$ {arch}"
2022-01-18 13:13:19 -08:00
2022-09-08 02:40:17 +10:00
echo " $$ image_tag" > " $@ "
2022-09-01 14:58:23 -05:00
2022-09-08 02:40:17 +10:00
# 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-01 14:58:23 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
$( foreach img, $^, " $$ (cat " $( img:push/%= %) ")" )
2022-09-01 14:58:23 -05:00
2022-09-08 02:40:17 +10:00
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 16:26:38 +04:00
# Helm charts that are available
charts = coder provisioner
2022-09-08 02:40:17 +10:00
# Shortcut for Helm chart package.
2023-08-16 16:26:38 +04:00
$(foreach chart,$(charts),build/$(chart)_helm.tgz) : build /%_helm .tgz : build /%_helm_ $( VERSION ) .tgz
2022-09-08 02:40:17 +10:00
rm -f " $@ "
ln " $<" " $@ "
# Helm chart package.
2023-08-16 16:26:38 +04:00
$(foreach chart,$(charts),build/$(chart)_helm_$(VERSION).tgz) : build /%_helm_ $( VERSION ) .tgz :
2022-09-08 02:40:17 +10:00
./scripts/helm.sh \
2022-09-01 14:58:23 -05:00
--version " $( VERSION) " \
2023-08-16 16:26:38 +04:00
--chart $* \
2022-09-08 02:40:17 +10:00
--output " $@ "
2022-09-01 14:58:23 -05:00
2025-03-21 15:33:07 +02:00
node_modules/.installed : package .json pnpm -lock .yaml
2025-01-03 05:37:25 -08:00
./scripts/pnpm_install.sh
2025-03-21 15:33:07 +02:00
touch " $@ "
2025-01-03 05:37:25 -08:00
2025-03-21 15:33:07 +02:00
offlinedocs/node_modules/.installed : offlinedocs /package .json offlinedocs /pnpm -lock .yaml
( cd offlinedocs/ && ../scripts/pnpm_install.sh)
touch " $@ "
2025-01-03 05:37:25 -08:00
2025-03-21 15:33:07 +02:00
site/node_modules/.installed : site /package .json site /pnpm -lock .yaml
( cd site/ && ../scripts/pnpm_install.sh)
touch " $@ "
2025-01-03 05:37:25 -08:00
2025-03-21 17:16:17 +02:00
scripts/apidocgen/node_modules/.installed : scripts /apidocgen /package .json scripts /apidocgen /pnpm -lock .yaml
( cd scripts/apidocgen && ../../scripts/pnpm_install.sh)
touch " $@ "
2025-01-14 11:30:39 -07:00
SITE_GEN_FILES := \
site/src/api/typesGenerated.ts \
site/src/api/rbacresourcesGenerated.ts \
site/src/api/countriesGenerated.ts \
site/src/theme/icons.json
site/out/index.html : \
site /node_modules /.installed \
site /static /install .sh \
$( SITE_GEN_FILES ) \
$( shell find ./site $( FIND_EXCLUSIONS ) -type f \( -name '*.ts ' -o -name '*.tsx ' \))
2025-01-03 12:27:26 -08:00
cd site/
2024-02-27 10:45:57 -07:00
# prevents this directory from getting to big, and causing "too much data" errors
rm -rf out/assets/
2023-08-02 13:28:16 -05:00
pnpm build
2022-01-05 09:20:56 -06:00
2025-01-03 05:37:25 -08:00
offlinedocs/out/index.html : offlinedocs /node_modules /.installed $( shell find ./offlinedocs $( FIND_EXCLUSIONS ) -type f ) $( shell find ./docs $( FIND_EXCLUSIONS ) -type f | sed 's : :\\ :g ')
2025-01-03 12:27:26 -08:00
cd offlinedocs/
2023-08-02 13:28:16 -05:00
../scripts/pnpm_install.sh
pnpm export
2023-07-19 13:57:57 -03:00
build/coder_docs_$(VERSION).tgz : offlinedocs /out /index .html
tar -czf " $@ " -C offlinedocs/out .
2022-09-08 02:40:17 +10: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 11:45:32 -06: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 16:31:22 -07:00
2025-01-03 18:12:59 +05:00
fmt : fmt /ts fmt /go fmt /terraform fmt /shfmt fmt /biome fmt /markdown
2022-09-08 02:40:17 +10:00
.PHONY : fmt
2022-01-05 09:20:56 -06:00
2023-02-18 18:32:09 -06:00
fmt/go :
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.go ]] && ! grep -q "DO NOT EDIT" " $( FILE) " ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/go $( RESET) $( FILE) " ; \
2025-07-03 11:28:00 -06:00
go run mvdan.cc/gofumpt@v0.8.0 -w -l " $( FILE) " ; \
2025-07-03 18:51:23 +02:00
fi
else
2024-09-24 21:39:34 +10:00
go mod tidy
2024-03-05 16:31:22 -07:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/go$(RESET)"
2023-02-18 18:32:09 -06:00
# VS Code users should check out
# https://github.com/mvdan/gofumpt#visual-studio-code
2024-12-30 12:56:22 +02:00
find . $( FIND_EXCLUSIONS) -type f -name '*.go' -print0 | \
2025-07-03 11:28:00 -06:00
xargs -0 grep -E --null -L '^// Code generated .* DO NOT EDIT\.$$' | \
xargs -0 go run mvdan.cc/gofumpt@v0.8.0 -w -l
2025-07-03 18:51:23 +02:00
endif
2023-02-18 18:32:09 -06:00
.PHONY : fmt /go
2025-01-03 05:37:25 -08:00
fmt/ts : site /node_modules /.installed
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single TypeScript/JavaScript file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.ts ]] || [[ " $( FILE) " == *.tsx ]] || [[ " $( FILE) " == *.js ]] || [[ " $( FILE) " == *.jsx ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/ts $( RESET) $( FILE) " ; \
( cd site/ && pnpm exec biome format --write "../ $( FILE) " ) ; \
fi
else
2024-08-15 13:26:29 -06:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/ts$(RESET)"
2024-03-05 16:31:22 -07:00
cd site
2024-08-15 13:26:29 -06:00
# Avoid writing files in CI to reduce file write activity
ifdef CI
pnpm run check --linter-enabled = false
else
pnpm run check : fix
endif
2025-07-03 18:51:23 +02:00
endif
2024-08-15 13:26:29 -06:00
.PHONY : fmt /ts
2024-03-05 16:31:22 -07:00
2025-01-03 05:37:25 -08:00
fmt/biome : site /node_modules /.installed
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single file with biome
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.ts ]] || [[ " $( FILE) " == *.tsx ]] || [[ " $( FILE) " == *.js ]] || [[ " $( FILE) " == *.jsx ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/biome $( RESET) $( FILE) " ; \
( cd site/ && pnpm exec biome format --write "../ $( FILE) " ) ; \
fi
else
2025-01-03 18:12:59 +05:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/biome$(RESET)"
2025-01-03 12:27:26 -08:00
cd site/
2022-01-03 18:54:27 -08:00
# Avoid writing files in CI to reduce file write activity
ifdef CI
2023-08-02 13:28:16 -05:00
pnpm run format : check
2022-01-03 18:54:27 -08:00
else
2024-03-05 16:31:22 -07:00
pnpm run format
2022-01-03 18:54:27 -08:00
endif
2025-07-03 18:51:23 +02:00
endif
2025-01-03 18:12:59 +05:00
.PHONY : fmt /biome
2022-01-03 18:54:27 -08:00
2022-04-11 16:06:15 -05:00
fmt/terraform : $( wildcard *.tf )
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single Terraform file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.tf ]] || [[ " $( FILE) " == *.tfvars ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/terraform $( RESET) $( FILE) " ; \
terraform fmt " $( FILE) " ; \
fi
else
2024-03-05 16:31:22 -07:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/terraform$(RESET)"
2022-04-11 16:06:15 -05:00
terraform fmt -recursive
2025-07-03 18:51:23 +02:00
endif
2022-05-02 14:04:45 -05:00
.PHONY : fmt /terraform
2022-04-11 16:06:15 -05:00
2022-11-09 18:39:42 +02:00
fmt/shfmt : $( SHELL_SRC_FILES )
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single shell script
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.sh ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/shfmt $( RESET) $( FILE) " ; \
shfmt -w " $( FILE) " ; \
fi
else
2024-03-05 16:31:22 -07:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/shfmt$(RESET)"
2022-05-27 20:15:19 +03:00
# Only do diff check in CI, errors on diff.
ifdef CI
2022-11-09 18:39:42 +02:00
shfmt -d $( SHELL_SRC_FILES )
2022-05-27 20:15:19 +03:00
else
2022-11-09 18:39:42 +02:00
shfmt -w $( SHELL_SRC_FILES )
2022-05-27 20:15:19 +03:00
endif
2025-07-03 18:51:23 +02:00
endif
2022-06-18 14:47:10 -05:00
.PHONY : fmt /shfmt
2022-05-27 20:15:19 +03:00
2025-01-03 05:37:25 -08:00
fmt/markdown : node_modules /.installed
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single markdown file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.md ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/markdown $( RESET) $( FILE) " ; \
pnpm exec markdown-table-formatter " $( FILE) " ; \
fi
else
2025-01-03 18:12:59 +05:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/markdown$(RESET)"
pnpm format-docs
2025-07-03 18:51:23 +02:00
endif
2025-01-03 18:12:59 +05:00
.PHONY : fmt /markdown
lint : lint /shellcheck lint /go lint /ts lint /examples lint /helm lint /site -icons lint /markdown
2022-06-18 14:47:10 -05:00
.PHONY : lint
2022-05-27 20:15:19 +03:00
2023-07-23 16:27:11 -05:00
lint/site-icons :
./scripts/check_site_icons.sh
.PHONY : lint /site -icons
2025-01-03 05:37:25 -08:00
lint/ts : site /node_modules /.installed
2025-01-03 12:27:26 -08:00
cd site/
2024-08-15 13:26:29 -06:00
pnpm lint
2023-06-12 12:09:54 -05:00
.PHONY : lint /ts
2022-05-27 20:15:19 +03:00
lint/go :
2022-08-19 10:49:08 -07:00
./scripts/check_enterprise_imports.sh
2024-09-12 15:34:03 +10:00
./scripts/check_codersdk_imports.sh
2025-03-11 13:17:40 +00:00
linter_ver = $( shell egrep -o 'GOLANGCI_LINT_VERSION=\S+' dogfood/coder/Dockerfile | cut -d '=' -f 2)
2024-07-10 14:50:38 -05:00
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v$$ linter_ver run
2022-05-27 20:15:19 +03:00
.PHONY : lint /go
2024-03-14 16:49:44 +02:00
lint/examples :
go run ./scripts/examplegen/main.go -lint
.PHONY : lint /examples
2022-05-27 20:15:19 +03:00
# Use shfmt to determine the shell files, takes editorconfig into consideration.
2022-11-09 18:39:42 +02:00
lint/shellcheck : $( SHELL_SRC_FILES )
2022-09-08 02:40:17 +10:00
echo "--- shellcheck"
2022-11-09 18:39:42 +02:00
shellcheck --external-sources $( SHELL_SRC_FILES)
2022-06-18 14:47:10 -05:00
.PHONY : lint /shellcheck
2022-03-28 14:21:00 -06:00
2023-06-12 12:09:54 -05:00
lint/helm :
2025-01-03 12:27:26 -08:00
cd helm/
2023-06-12 12:09:54 -05:00
make lint
.PHONY : lint /helm
2025-01-03 05:37:25 -08:00
lint/markdown : node_modules /.installed
2025-01-03 18:12:59 +05:00
pnpm lint-docs
.PHONY : lint /markdown
2023-07-06 10:59:08 +03: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 := \
2025-01-13 13:08:16 +02:00
coderd/database/dump.sql \
2023-07-06 10:59:08 +03:00
coderd/database/querier.go \
coderd/database/unique_constraint.go \
coderd/database/dbmetrics/dbmetrics.go \
coderd/database/dbauthz/dbauthz.go \
coderd/database/dbmock/dbmock.go
2024-11-18 10:54:11 +04:00
TAILNETTEST_MOCKS := \
tailnet/tailnettest/coordinatormock.go \
tailnet/tailnettest/coordinateemock.go \
tailnet/tailnettest/workspaceupdatesprovidermock.go \
tailnet/tailnettest/subscriptionmock.go
2024-12-30 11:45:06 +02:00
GEN_FILES := \
2023-10-30 12:14:45 +04:00
tailnet/proto/tailnet.pb.go \
agent/proto/agent.pb.go \
2022-09-08 02:40:17 +10:00
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
2024-10-02 16:45:13 +10:00
vpn/vpn.pb.go \
2025-01-14 11:30:39 -07:00
$( DB_GEN_FILES) \
$( SITE_GEN_FILES) \
2023-04-11 08:57:23 -05:00
coderd/rbac/object_gen.go \
2024-05-15 11:09:42 -05:00
codersdk/rbacresources_gen.go \
2024-10-05 08:52:04 -07:00
docs/admin/integrations/prometheus.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
2023-01-03 15:11:13 +02:00
coderd/apidoc/swagger.json \
2025-03-21 17:16:17 +02:00
docs/manifest.json \
2024-05-22 13:45:47 -04:00
provisioner/terraform/testdata/version \
2023-09-04 20:15:29 +03:00
site/e2e/provisionerGenerated.ts \
2024-01-22 11:07:50 +04:00
examples/examples.gen.json \
2024-11-18 10:54:11 +04:00
$( TAILNETTEST_MOCKS) \
2025-02-10 11:29:30 +00:00
coderd/database/pubsub/psmock/psmock.go \
2025-03-18 13:00:21 +00:00
agent/agentcontainers/acmock/acmock.go \
2025-04-08 10:30:05 +02:00
agent/agentcontainers/dcspec/dcspec_gen.go \
2025-04-15 13:27:23 +02:00
coderd/httpmw/loggermw/loggermock/loggermock.go
2025-01-14 11:30:39 -07:00
2024-12-30 11:45:06 +02:00
# all gen targets should be added here and to gen/mark-fresh
2025-03-21 15:04:30 +02:00
gen : gen /db gen /golden -files $( GEN_FILES )
2022-09-08 02:40:17 +10:00
.PHONY : gen
2024-12-31 15:47:47 +02:00
gen/db : $( DB_GEN_FILES )
.PHONY : gen /db
2025-03-21 15:04:30 +02:00
gen/golden-files : \
cli /testdata /.gen -golden \
coderd /.gen -golden \
coderd /notifications /.gen -golden \
enterprise /cli /testdata /.gen -golden \
enterprise /tailnet /testdata /.gen -golden \
helm /coder /tests /testdata /.gen -golden \
helm /provisioner /tests /testdata /.gen -golden \
provisioner /terraform /testdata /.gen -golden \
tailnet /testdata /.gen -golden
.PHONY : gen /golden -files
2022-09-08 02:40:17 +10:00
# 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 15:11:13 +02:00
files = "\
2023-10-30 12:14:45 +04:00
tailnet/proto/tailnet.pb.go \
agent/proto/agent.pb.go \
2023-01-03 15:11:13 +02:00
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
2024-10-02 16:45:13 +10:00
vpn/vpn.pb.go \
2023-08-25 10:10:15 +04:00
coderd/database/dump.sql \
$( DB_GEN_FILES) \
2023-01-03 15:11:13 +02:00
site/src/api/typesGenerated.ts \
2023-04-11 08:57:23 -05:00
coderd/rbac/object_gen.go \
2024-07-02 16:29:00 +02:00
codersdk/rbacresources_gen.go \
2024-07-23 05:07:52 -10:00
site/src/api/rbacresourcesGenerated.ts \
2024-11-15 23:35:21 +05:30
site/src/api/countriesGenerated.ts \
2024-10-05 08:52:04 -07:00
docs/admin/integrations/prometheus.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
2023-01-03 15:11:13 +02:00
coderd/apidoc/swagger.json \
2025-03-21 17:16:17 +02:00
docs/manifest.json \
2023-08-18 10:50:43 +02:00
site/e2e/provisionerGenerated.ts \
2023-10-06 13:46:37 -06:00
site/src/theme/icons.json \
2023-09-04 20:15:29 +03:00
examples/examples.gen.json \
2024-11-18 10:54:11 +04:00
$( TAILNETTEST_MOCKS) \
2024-10-15 12:49:26 +04:00
coderd/database/pubsub/psmock/psmock.go \
2025-02-10 12:45:44 +00:00
agent/agentcontainers/acmock/acmock.go \
2025-03-18 13:00:21 +00:00
agent/agentcontainers/dcspec/dcspec_gen.go \
2025-04-15 13:27:23 +02:00
coderd/httpmw/loggermw/loggermock/loggermock.go \
2024-10-03 21:09:52 -05:00
"
2022-09-08 02:40:17 +10: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
2025-01-03 12:27:26 -08:00
touch " $$ file"
2022-09-08 02:40:17 +10:00
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-23 08:30:32 +10:00
go run ./coderd/database/gen/dump/main.go
2025-03-21 15:33:07 +02:00
touch " $@ "
2022-09-08 02:40:17 +10:00
# Generates Go code for querying the database.
2023-10-17 14:41:35 -06:00
# coderd/database/queries.sql.go
# coderd/database/models.go
2023-06-20 11:24:33 -05:00
coderd/database/querier.go : coderd /database /sqlc .yaml coderd /database /dump .sql $( wildcard coderd /database /queries /*.sql )
2022-09-08 02:40:17 +10:00
./coderd/database/generate.sh
2025-03-21 15:33:07 +02:00
touch " $@ "
2022-09-08 02:40:17 +10:00
2023-06-13 13:57:43 -05:00
coderd/database/dbmock/dbmock.go : coderd /database /db .go coderd /database /querier .go
2023-05-23 12:06:33 +04:00
go generate ./coderd/database/dbmock/
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-05-23 12:06:33 +04:00
2024-05-16 13:42:42 -05:00
coderd/database/pubsub/psmock/psmock.go : coderd /database /pubsub /pubsub .go
go generate ./coderd/database/pubsub/psmock
2025-03-21 15:33:07 +02:00
touch " $@ "
2024-05-16 13:42:42 -05:00
2025-02-10 11:29:30 +00:00
agent/agentcontainers/acmock/acmock.go : agent /agentcontainers /containers .go
go generate ./agent/agentcontainers/acmock/
2025-03-21 15:33:07 +02:00
touch " $@ "
2025-02-10 11:29:30 +00:00
2025-04-15 13:27:23 +02:00
coderd/httpmw/loggermw/loggermock/loggermock.go : coderd /httpmw /loggermw /logger .go
go generate ./coderd/httpmw/loggermw/loggermock/
2025-04-08 10:30:05 +02:00
touch " $@ "
2025-03-24 13:41:45 +02:00
agent/agentcontainers/dcspec/dcspec_gen.go : \
node_modules /.installed \
agent /agentcontainers /dcspec /devContainer .base .schema .json \
agent /agentcontainers /dcspec /gen .sh \
agent /agentcontainers /dcspec /doc .go
DCSPEC_QUIET = true go generate ./agent/agentcontainers/dcspec/
2025-03-21 15:33:07 +02:00
touch " $@ "
2025-03-18 13:00:21 +00:00
2024-11-18 10:54:11 +04:00
$(TAILNETTEST_MOCKS) : tailnet /coordinator .go tailnet /service .go
2024-01-22 11:07:50 +04:00
go generate ./tailnet/tailnettest/
2025-03-21 15:33:07 +02:00
touch " $@ "
2024-01-22 11:07:50 +04:00
2023-10-30 12:14:45 +04: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-05-02 13:23:13 -05:00
provisionersdk/proto/provisioner.pb.go : provisionersdk /proto /provisioner .proto
2022-01-29 17:52:14 -06:00
protoc \
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./provisionersdk/proto/provisioner.proto
2022-01-18 13:13:19 -08:00
2022-09-08 02:40:17 +10:00
provisionerd/proto/provisionerd.pb.go : provisionerd /proto /provisionerd .proto
protoc \
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./provisionerd/proto/provisionerd.proto
2022-05-02 13:23:13 -05:00
2024-10-01 19:40:42 +04:00
vpn/vpn.pb.go : vpn /vpn .proto
protoc \
--go_out= . \
--go_opt= paths = source_relative \
./vpn/vpn.proto
2025-01-03 05:37:25 -08:00
site/src/api/typesGenerated.ts : site /node_modules /.installed $( wildcard scripts /apitypings /*) $( shell find ./codersdk $( FIND_EXCLUSIONS ) -type f -name '*.go ')
2024-12-11 14:39:21 -06:00
# -C sets the directory for the go run command
go run -C ./scripts/apitypings main.go > $@
2025-03-21 15:33:07 +02:00
( cd site/ && pnpm exec biome format --write src/api/typesGenerated.ts)
touch " $@ "
2022-03-28 14:14:40 -05:00
2025-01-03 05:37:25 -08:00
site/e2e/provisionerGenerated.ts : site /node_modules /.installed provisionerd /proto /provisionerd .pb .go provisionersdk /proto /provisioner .pb .go
2025-03-21 15:33:07 +02:00
( cd site/ && pnpm run gen:provisioner)
touch " $@ "
2023-08-18 10:50:43 +02:00
2025-01-03 05:37:25 -08:00
site/src/theme/icons.json : site /node_modules /.installed $( wildcard scripts /gensite /*) $( wildcard site /static /icon /*)
2023-10-17 14:41:35 -06:00
go run ./scripts/gensite/ -icons " $@ "
2025-03-21 15:33:07 +02:00
( cd site/ && pnpm exec biome format --write src/theme/icons.json)
touch " $@ "
2023-10-06 13:46:37 -06:00
2023-09-04 20:15:29 +03: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
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-09-04 20:15:29 +03:00
2024-11-15 23:35:21 +05:30
coderd/rbac/object_gen.go : scripts /typegen /rbacobject .gotmpl scripts /typegen /main .go coderd /rbac /object .go coderd /rbac /policy /policy .go
2024-12-18 07:20:26 -06:00
tempdir = $( shell mktemp -d /tmp/typegen_rbac_object.XXXXXX)
go run ./scripts/typegen/main.go rbac object > " $$ tempdir/object_gen.go"
mv -v " $$ tempdir/object_gen.go" coderd/rbac/object_gen.go
rmdir -v " $$ tempdir"
2025-03-21 15:33:07 +02:00
touch " $@ "
2024-05-15 11:09:42 -05:00
2024-11-15 23:35:21 +05:30
codersdk/rbacresources_gen.go : scripts /typegen /codersdk .gotmpl scripts /typegen /main .go coderd /rbac /object .go coderd /rbac /policy /policy .go
2024-10-03 20:28:04 -05:00
# Do no overwrite codersdk/rbacresources_gen.go directly, as it would make the file empty, breaking
# the `codersdk` package and any parallel build targets.
2024-11-15 23:35:21 +05:30
go run scripts/typegen/main.go rbac codersdk > /tmp/rbacresources_gen.go
2024-10-03 20:28:04 -05:00
mv /tmp/rbacresources_gen.go codersdk/rbacresources_gen.go
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-04-11 08:57:23 -05:00
2025-01-03 05:37:25 -08:00
site/src/api/rbacresourcesGenerated.ts : site /node_modules /.installed scripts /typegen /codersdk .gotmpl scripts /typegen /main .go coderd /rbac /object .go coderd /rbac /policy /policy .go
2024-11-15 23:35:21 +05:30
go run scripts/typegen/main.go rbac typescript > " $@ "
2025-03-21 15:33:07 +02:00
( cd site/ && pnpm exec biome format --write src/api/rbacresourcesGenerated.ts)
touch " $@ "
2024-11-15 23:35:21 +05:30
2025-01-03 05:37:25 -08:00
site/src/api/countriesGenerated.ts : site /node_modules /.installed scripts /typegen /countries .tstmpl scripts /typegen /main .go codersdk /countries .go
2024-11-15 23:35:21 +05:30
go run scripts/typegen/main.go countries > " $@ "
2025-03-21 15:33:07 +02:00
( cd site/ && pnpm exec biome format --write src/api/countriesGenerated.ts)
touch " $@ "
2024-07-23 05:07:52 -10:00
2025-01-03 05:37:25 -08:00
docs/admin/integrations/prometheus.md : node_modules /.installed scripts /metricsdocgen /main .go scripts /metricsdocgen /metrics
2022-11-30 17:39:51 +01:00
go run scripts/metricsdocgen/main.go
2025-01-03 18:12:59 +05:00
pnpm exec markdownlint-cli2 --fix ./docs/admin/integrations/prometheus.md
pnpm exec markdown-table-formatter ./docs/admin/integrations/prometheus.md
2025-03-21 15:33:07 +02:00
touch " $@ "
2022-11-30 17:39:51 +01:00
2025-03-21 17:16:17 +02:00
docs/reference/cli/index.md : node_modules /.installed scripts /clidocgen /main .go examples /examples .gen .json $( GO_SRC_FILES )
2023-09-07 17:28:22 -04:00
CI = true BASE_PATH = "." go run ./scripts/clidocgen
2025-01-03 18:12:59 +05:00
pnpm exec markdownlint-cli2 --fix ./docs/reference/cli/*.md
pnpm exec markdown-table-formatter ./docs/reference/cli/*.md
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-01-27 15:10:40 -03:00
2025-01-03 05:37:25 -08:00
docs/admin/security/audit-logs.md : node_modules /.installed coderd /database /querier .go scripts /auditdocgen /main .go enterprise /audit /table .go coderd /rbac /object_gen .go
2023-01-26 18:12:12 -05:00
go run scripts/auditdocgen/main.go
2025-01-03 18:12:59 +05:00
pnpm exec markdownlint-cli2 --fix ./docs/admin/security/audit-logs.md
pnpm exec markdown-table-formatter ./docs/admin/security/audit-logs.md
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-01-26 18:12:12 -05:00
2025-03-21 17:16:17 +02:00
coderd/apidoc/.gen : \
node_modules /.installed \
scripts /apidocgen /node_modules /.installed \
$( wildcard coderd /*.go ) \
$( wildcard enterprise /coderd /*.go ) \
$( wildcard codersdk /*.go ) \
$( wildcard enterprise /wsproxy /wsproxysdk /*.go ) \
$( DB_GEN_FILES ) \
coderd /rbac /object_gen .go \
.swaggo \
scripts /apidocgen /generate .sh \
$( wildcard scripts /apidocgen /postprocess /*) \
$( wildcard scripts /apidocgen /markdown -template /*)
2022-12-19 18:43:46 +01:00
./scripts/apidocgen/generate.sh
2025-01-03 18:12:59 +05:00
pnpm exec markdownlint-cli2 --fix ./docs/reference/api/*.md
pnpm exec markdown-table-formatter ./docs/reference/api/*.md
2025-03-21 17:16:17 +02:00
touch " $@ "
docs/manifest.json : site /node_modules /.installed coderd /apidoc /.gen docs /reference /cli /index .md
( cd site/ && pnpm exec biome format --write ../docs/manifest.json)
touch " $@ "
coderd/apidoc/swagger.json : site /node_modules /.installed coderd /apidoc /.gen
( cd site/ && pnpm exec biome format --write ../coderd/apidoc/swagger.json)
2025-03-21 15:33:07 +02:00
touch " $@ "
2022-12-19 18:43:46 +01:00
2025-03-21 15:04:30 +02:00
update-golden-files :
2025-04-23 14:01:28 +03:00
echo 'WARNING: This target is deprecated. Use "make gen/golden-files" instead.' >& 2
echo 'Running "make gen/golden-files"' >& 2
2025-03-21 15:04:30 +02:00
make gen/golden-files
2022-11-04 19:48:36 +02:00
.PHONY : update -golden -files
2025-01-02 11:05:11 +02:00
clean/golden-files :
find . -type f -name '.gen-golden' -delete
find \
cli/testdata \
coderd/notifications/testdata \
coderd/testdata \
enterprise/cli/testdata \
enterprise/tailnet/testdata \
helm/coder/tests/testdata \
helm/provisioner/tests/testdata \
provisioner/terraform/testdata \
tailnet/testdata \
-type f -name '*.golden' -delete
.PHONY : clean /golden -files
2023-07-06 10:59:08 +03:00
cli/testdata/.gen-golden : $( wildcard cli /testdata /*.golden ) $( wildcard cli /*.tpl ) $( GO_SRC_FILES ) $( wildcard cli /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./cli -run= "Test(CommandHelp|ServerYAML|ErrorExamples|.*Golden)" -update
2022-11-04 19:48:36 +02:00
touch " $@ "
2023-07-06 10:59:08 +03:00
enterprise/cli/testdata/.gen-golden : $( wildcard enterprise /cli /testdata /*.golden ) $( wildcard cli /*.tpl ) $( GO_SRC_FILES ) $( wildcard enterprise /cli /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./enterprise/cli -run= "TestEnterpriseCommandHelp" -update
2023-06-09 11:35:20 -05:00
touch " $@ "
2023-12-06 15:04:28 +04:00
tailnet/testdata/.gen-golden : $( wildcard tailnet /testdata /*.golden .html ) $( GO_SRC_FILES ) $( wildcard tailnet /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./tailnet -run= "TestDebugTemplate" -update
2023-12-06 15:04:28 +04:00
touch " $@ "
2023-11-28 22:37:20 +04:00
enterprise/tailnet/testdata/.gen-golden : $( wildcard enterprise /tailnet /testdata /*.golden .html ) $( GO_SRC_FILES ) $( wildcard enterprise /tailnet /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./enterprise/tailnet -run= "TestDebugTemplate" -update
2023-11-28 22:37:20 +04:00
touch " $@ "
2023-08-10 13:59:43 +04: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 )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./helm/coder/tests -run= TestUpdateGoldenFiles -update
2023-08-10 13:59:43 +04:00
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 )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./helm/provisioner/tests -run= TestUpdateGoldenFiles -update
2023-03-13 13:48:44 +00:00
touch " $@ "
2023-08-24 13:36:40 +03:00
coderd/.gen-golden : $( wildcard coderd /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard coderd /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./coderd -run= "Test.*Golden $$ " -update
2024-10-10 00:31:12 +02:00
touch " $@ "
coderd/notifications/.gen-golden : $( wildcard coderd /notifications /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard coderd /notifications /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./coderd/notifications -run= "Test.*Golden $$ " -update
2023-08-24 13:36:40 +03:00
touch " $@ "
2023-09-11 09:37:14 +02:00
provisioner/terraform/testdata/.gen-golden : $( wildcard provisioner /terraform /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard provisioner /terraform /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./provisioner/terraform -run= "Test.*Golden $$ " -update
2023-09-11 09:37:14 +02:00
touch " $@ "
2024-05-22 13:45:47 -04:00
provisioner/terraform/testdata/version :
if [[ " $( shell cat provisioner/terraform/testdata/version.txt) " != " $( shell terraform version -json | jq -r '.terraform_version' ) " ]] ; then
./provisioner/terraform/testdata/generate.sh
fi
.PHONY : provisioner /terraform /testdata /version
2025-05-06 16:53:26 +02:00
# Set the retry flags if TEST_RETRIES is set
ifdef TEST_RETRIES
GOTESTSUM_RETRY_FLAGS := --rerun-fails= $( TEST_RETRIES)
else
GOTESTSUM_RETRY_FLAGS :=
endif
2023-07-07 12:16:16 +01:00
test :
2025-05-06 16:53:26 +02:00
$( GIT_FLAGS) gotestsum --format standard-quiet $( GOTESTSUM_RETRY_FLAGS) --packages= "./..." -- -v -short -count= 1 $(if $( RUN) ,-run $( RUN))
2022-06-18 14:47:10 -05:00
.PHONY : test
2022-05-21 00:39:51 +01:00
2025-01-20 09:06:33 +02:00
test-cli :
2025-05-06 16:53:26 +02:00
$( GIT_FLAGS) gotestsum --format standard-quiet $( GOTESTSUM_RETRY_FLAGS) --packages= "./cli/..." -- -v -short -count= 1
2025-01-20 09:06:33 +02:00
.PHONY : test -cli
2023-12-19 14:31:55 -06: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 15:53:26 -06: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 16:55:13 -06:00
.PHONY : sqlc -vet
2023-12-12 15:53:26 -06:00
2022-07-22 12:47:03 +03:00
# When updating -timeout for this test, keep in sync with
# test-go-postgres (.github/workflows/coder.yaml).
2023-06-09 16:46:44 -05:00
# Do add coverage flags so that test caching works.
2023-07-07 12:16:16 +01:00
test-postgres : test -postgres -docker
2022-11-13 14:23:23 -06:00
# The postgres test is prone to failure, so we limit parallelism for
# more consistent execution.
2025-07-09 09:46:31 +02:00
$( GIT_FLAGS) gotestsum \
2022-12-07 15:04:39 +01:00
--junitfile= "gotests.xml" \
2023-04-03 14:07:25 +03:00
--jsonfile= "gotests.json" \
2025-05-06 16:53:26 +02:00
$( GOTESTSUM_RETRY_FLAGS) \
2022-12-07 15:04:39 +01:00
--packages= "./..." -- \
2023-06-09 16:46:44 -05:00
-timeout= 20m \
2023-07-07 12:16:16 +01:00
-count= 1
2022-06-18 14:47:10 -05:00
.PHONY : test -postgres
2022-05-21 00:39:51 +01:00
2024-04-23 12:43:14 +01:00
test-migrations : test -postgres -docker
echo "--- test migrations"
2024-04-24 08:31:01 +01:00
set -euo pipefail
2024-05-17 10:24:56 +01:00
COMMIT_FROM = $( shell git log -1 --format= '%h' HEAD)
echo "COMMIT_FROM= $$ {COMMIT_FROM}"
COMMIT_TO = $( shell git log -1 --format= '%h' origin/main)
echo "COMMIT_TO= $$ {COMMIT_TO}"
if [[ " $$ {COMMIT_FROM}" == " $$ {COMMIT_TO}" ]] ; then echo "Nothing to do!" ; exit 0; fi
2024-04-24 08:31:01 +01: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"
2025-01-03 12:27:26 -08:00
.PHONY : test -migrations
2024-04-23 12:43:14 +01:00
2024-03-21 14:53:16 +00:00
# NOTE: we set --memory to the same size as a GitHub runner.
2022-05-21 00:39:51 +01:00
test-postgres-docker :
2024-06-26 16:22:24 +01:00
docker rm -f test-postgres-docker-${ POSTGRES_VERSION } || true
2025-01-17 17:22:50 +02:00
# Try pulling up to three times to avoid CI flakes.
2025-06-11 23:06:31 +10:00
docker pull ${ POSTGRES_IMAGE } || {
2025-01-17 17:22:50 +02:00
retries = 2
for try in $( seq 1 ${ retries } ) ; do
echo "Failed to pull image, retrying ( ${ try } / ${ retries } )..."
sleep 1
2025-06-11 23:06:31 +10:00
if docker pull ${ POSTGRES_IMAGE } ; then
2025-01-17 17:22:50 +02:00
break
fi
done
}
2025-01-17 16:07:11 +02:00
# Make sure to not overallocate work_mem and max_connections as each
# connection will be allowed to use this much memory. Try adjusting
# shared_buffers instead, if needed.
#
# - work_mem=8MB * max_connections=1000 = 8GB
# - shared_buffers=2GB + effective_cache_size=1GB = 3GB
#
# This leaves 5GB for the rest of the system _and_ storing the
# database in memory (--tmpfs).
#
# https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM
2022-05-21 00:39:51 +01:00
docker run \
--env POSTGRES_PASSWORD = postgres \
--env POSTGRES_USER = postgres \
--env POSTGRES_DB = postgres \
--env PGDATA = /tmp \
2022-06-17 20:57:38 +01:00
--tmpfs /tmp \
2022-05-21 00:39:51 +01:00
--publish 5432:5432 \
2024-06-26 16:22:24 +01:00
--name test-postgres-docker-${ POSTGRES_VERSION } \
2022-06-17 20:57:38 +01:00
--restart no \
2022-05-21 00:39:51 +01:00
--detach \
2024-03-21 14:53:16 +00:00
--memory 16GB \
2025-06-11 23:06:31 +10:00
${ POSTGRES_IMAGE } \
2025-01-17 16:07:11 +02:00
-c shared_buffers = 2GB \
2023-05-14 15:32:44 -05:00
-c effective_cache_size = 1GB \
2025-01-17 16:07:11 +02:00
-c work_mem = 8MB \
2022-06-17 20:57:38 +01: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 12:07:39 -05:00
while ! pg_isready -h 127.0.0.1
do
echo " $( date) - waiting for database to start"
sleep 0.5
done
2022-06-18 14:47:10 -05:00
.PHONY : test -postgres -docker
2022-05-21 00:39:51 +01:00
2023-07-07 11:15:50 +01:00
# Make sure to keep this in sync with test-go-race from .github/workflows/ci.yaml.
2023-07-07 12:16:16 +01:00
test-race :
2024-10-18 10:45:31 +04:00
$( GIT_FLAGS) gotestsum --junitfile= "gotests.xml" -- -race -count= 1 -parallel 4 -p 4 ./...
2023-07-07 11:15:50 +01:00
.PHONY : test -race
2024-05-06 23:21:17 -07:00
test-tailnet-integration :
env \
CODER_TAILNET_TESTS = true \
CODER_MAGICSOCK_DEBUG_LOGGING = true \
TS_DEBUG_NETCHECK = true \
GOTRACEBACK = single \
go test \
-exec "sudo -E" \
-timeout= 5m \
-count= 1 \
./tailnet/test/integration
2025-01-03 12:27:26 -08:00
.PHONY : test -tailnet -integration
2024-05-06 23:21:17 -07:00
2023-07-07 12:16:16 +01: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-21 00:39:51 +01:00
test-clean :
go clean -testcache
2022-06-18 14:47:10 -05:00
.PHONY : test -clean
2024-06-26 09:00:42 +01:00
2025-01-23 09:45:50 -07:00
site/e2e/bin/coder : go .mod go .sum $( GO_SRC_FILES )
go build -o $@ \
-tags ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube \
./enterprise/cmd/coder
test-e2e : site /e 2e /bin /coder site /node_modules /.installed site /out /index .html
2025-01-03 12:27:26 -08:00
cd site/
ifdef CI
DEBUG = pw:api pnpm playwright:test --forbid-only --workers 1
else
pnpm playwright : test
endif
2024-06-26 09:00:42 +01:00
.PHONY : test -e 2e
2025-01-28 16:38:37 +01:00
2025-03-11 13:17:40 +00:00
dogfood/coder/nix.hash : flake .nix flake .lock
sha256sum flake.nix flake.lock >./dogfood/coder/nix.hash