Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Build enterprise coder binary by default #3517

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 5 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions LICENSE.enterprise
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LICENSE (GNU Affero General Public License) applies to
all files in this repository, except for those in or under
any directory named "enterprise", which are Copyright Coder
Technologies, Inc., All Rights Reserved.

We plan to release an enterprise license covering these files
as soon as possible. Watch this space.


27 changes: 27 additions & 0 deletions enterprise/cmd/coder/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"errors"
"fmt"
"math/rand"
"os"
"time"
_ "time/tzdata"

"github.com/coder/coder/cli"
"github.com/coder/coder/cli/cliui"
)

func main() {
rand.Seed(time.Now().UnixMicro())

cmd, err := cli.Root().ExecuteC()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we plan on having a separate CLI package to maintain? How do we imagine this working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will eventually be a separate enterprise cli package, because CLI commands for enterprise features will be in it. It will import all the core commands from the AGPL cli package.

if err != nil {
if errors.Is(err, cliui.Canceled) {
os.Exit(1)
}
cobraErr := cli.FormatCobraError(err, cmd)
_, _ = fmt.Fprintln(os.Stderr, cobraErr)
os.Exit(1)
}
}
21 changes: 17 additions & 4 deletions scripts/archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This script creates an archive containing the given binary renamed to
# `coder(.exe)?`, as well as the README.md and LICENSE files from the repo root.
#
# Usage: ./archive.sh --format tar.gz [--output path/to/output.tar.gz] [--sign-darwin] path/to/binary
# Usage: ./archive.sh --format tar.gz [--output path/to/output.tar.gz] [--sign-darwin] [--agpl] path/to/binary
#
# The --format parameter must be set, and must either be "zip" or "tar.gz".
#
Expand All @@ -14,7 +14,9 @@
# utility and then notarized using the `gon` utility, which may take a while.
# $AC_APPLICATION_IDENTITY must be set and the signing certificate must be
# imported for this to work. Also, the input binary must already be signed with
# the `codesign` tool.
# the `codesign` tool.=
#
# If the --agpl parameter is specified, only includes AGPL license.
#
# The absolute output path is printed on success.

Expand All @@ -25,8 +27,9 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
format=""
output_path=""
sign_darwin=0
agpl="${CODER_BUILD_AGPL:-0}"

args="$(getopt -o "" -l format:,output:,sign-darwin -- "$@")"
args="$(getopt -o "" -l format:,output:,sign-darwin,agpl -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand All @@ -50,6 +53,10 @@ while true; do
sign_darwin=1
shift
;;
--agpl)
agpl=1
shift
;;
--)
shift
break
Expand Down Expand Up @@ -101,7 +108,13 @@ cdroot
temp_dir="$(mktemp -d)"
ln -s "$input_file" "$temp_dir/$output_file"
ln -s "$(realpath README.md)" "$temp_dir/"
ln -s "$(realpath LICENSE)" "$temp_dir/"
if [[ "$agpl" == 1 ]]; then
ln -s "$(realpath LICENSE.agpl)" "$temp_dir/LICENSE"
else
ln -s "$(realpath LICENSE)" "$temp_dir/"
ln -s "$(realpath LICENSE.agpl)" "$temp_dir/"
ln -s "$(realpath LICENSE.enterprise)" "$temp_dir/"
fi

# Ensure parent output dir and non-existent output file.
mkdir -p "$(dirname "$output_path")"
Expand Down
18 changes: 15 additions & 3 deletions scripts/build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This script builds a single Go binary of Coder with the given parameters.
#
# Usage: ./build_go.sh [--version 1.2.3-devel+abcdef] [--os linux] [--arch amd64] [--output path/to/output] [--slim]
# Usage: ./build_go.sh [--version 1.2.3-devel+abcdef] [--os linux] [--arch amd64] [--output path/to/output] [--slim] [--agpl]
#
# Defaults to linux:amd64 with slim disabled, but can be controlled with GOOS,
# GOARCH and CODER_SLIM_BUILD=1. If no version is specified, defaults to the
Expand All @@ -19,6 +19,9 @@
# If the --sign-darwin parameter is specified and the OS is darwin, binaries
# will be signed using the `codesign` utility. $AC_APPLICATION_IDENTITY must be
# set and the signing certificate must be imported for this to work.
#
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
# Coder enterprise features).

set -euo pipefail
# shellcheck source=scripts/lib.sh
Expand All @@ -31,8 +34,9 @@ arch="${GOARCH:-amd64}"
slim="${CODER_SLIM_BUILD:-0}"
sign_darwin=0
output_path=""
agpl="${CODER_BUILD_AGPL:-0}"

args="$(getopt -o "" -l version:,os:,arch:,output:,slim,sign-darwin -- "$@")"
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand All @@ -56,6 +60,10 @@ while true; do
slim=1
shift
;;
--agpl)
agpl=1
shift
;;
--sign-darwin)
if [[ "${AC_APPLICATION_IDENTITY:-}" == "" ]]; then
error "AC_APPLICATION_IDENTITY must be set when --sign-darwin is supplied"
Expand Down Expand Up @@ -115,9 +123,13 @@ elif [[ "$arch" == "armv"* ]] || [[ "$arch" == "arm64v"* ]]; then
arch="${arch//v*/}"
fi

cmd_path="./enterprise/cmd/coder"
if [[ "$agpl" == 1 ]]; then
cmd_path="./cmd/coder"
fi
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" GOARM="$arm_version" go build \
"${build_args[@]}" \
./cmd/coder 1>&2
"$cmd_path" 1>&2

if [[ "$sign_darwin" == 1 ]] && [[ "$os" == "darwin" ]]; then
codesign -s "$AC_APPLICATION_IDENTITY" -f -v --timestamp --options runtime "$output_path"
Expand Down
18 changes: 16 additions & 2 deletions scripts/build_go_matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This script builds multiple Go binaries for Coder with the given OS and
# architecture combinations.
#
# Usage: ./build_go_matrix.sh [--version 1.2.3-devel+abcdef] [--output dist/] [--slim] [--sign-darwin] [--archive] [--package-linux] os1:arch1,arch2 os2:arch1 os1:arch3
# Usage: ./build_go_matrix.sh [--version 1.2.3-devel+abcdef] [--output dist/] [--slim] [--sign-darwin] [--archive] [--package-linux] [--agpl] os1:arch1,arch2 os2:arch1 os1:arch3
#
# If no OS:arch combinations are provided, nothing will happen and no error will
# be returned. Slim builds are disabled by default. If no version is specified,
Expand All @@ -30,6 +30,9 @@
#
# If the --package-linux parameter is specified, all linux binaries will be
# packaged using ./package.sh. Requires the nfpm binary.
#
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
# Coder enterprise features).

set -euo pipefail
# shellcheck source=scripts/lib.sh
Expand All @@ -41,8 +44,9 @@ slim=0
sign_darwin=0
archive=0
package_linux=0
agpl=0

args="$(getopt -o "" -l version:,output:,slim,sign-darwin,archive,package-linux -- "$@")"
args="$(getopt -o "" -l version:,output:,slim,sign-darwin,archive,package-linux,agpl -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand Down Expand Up @@ -73,6 +77,10 @@ while true; do
package_linux=1
shift
;;
--agpl)
agpl=1
shift
;;
--)
shift
break
Expand Down Expand Up @@ -167,6 +175,9 @@ fi
if [[ "$sign_darwin" == 1 ]]; then
build_args+=(--sign-darwin)
fi
if [[ "$agpl" == 1 ]]; then
build_args+=(--agpl)
fi

# Build each spec.
for spec in "${specs[@]}"; do
Expand Down Expand Up @@ -208,6 +219,9 @@ for spec in "${specs[@]}"; do
if [[ "$sign_darwin" == 1 ]] && [[ "$spec_os" == "darwin" ]]; then
archive_args+=(--sign-darwin)
fi
if [[ "$agpl" == 1 ]]; then
archive_args+=(--agpl)
fi

log "--- Creating archive for $spec_os $spec_arch ($spec_output_archive)"
execrelative ./archive.sh \
Expand Down
19 changes: 16 additions & 3 deletions scripts/build_go_slim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This script builds multiple "slim" Go binaries for Coder with the given OS and
# architecture combinations. This wraps ./build_go_matrix.sh.
#
# Usage: ./build_go_slim.sh [--version 1.2.3-devel+abcdef] [--output dist/] [--compress 22] os1:arch1,arch2 os2:arch1 os1:arch3
# Usage: ./build_go_slim.sh [--version 1.2.3-devel+abcdef] [--output dist/] [--compress 22] [--agpl] os1:arch1,arch2 os2:arch1 os1:arch3
#
# If no OS:arch combinations are provided, nothing will happen and no error will
# be returned. If no version is specified, defaults to the version from
Expand All @@ -19,6 +19,9 @@
# When the --compress <level> parameter is provided, the binaries in site/bin
# will be compressed using zstd into site/bin/coder.tar.zst, this helps reduce
# final binary size significantly.
#
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
# Coder enterprise features).

set -euo pipefail
shopt -s nullglob
Expand All @@ -28,8 +31,9 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
version=""
output_path=""
compress=0
agpl=0

args="$(getopt -o "" -l version:,output:,compress: -- "$@")"
args="$(getopt -o "" -l version:,output:,compress:,agpl -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
Expand All @@ -45,6 +49,10 @@ while true; do
compress="$2"
shift 2
;;
--agpl)
agpl=1
shift
;;
--)
shift
break
Expand Down Expand Up @@ -85,10 +93,15 @@ else
output_path="$(realpath "${output_path}coder-slim_{version}_{os}_{arch}")"
fi

build_args=(--slim)
if [[ "$agpl" == 1 ]]; then
build_args+=(--agpl)
fi

./scripts/build_go_matrix.sh \
--version "$version" \
--output "$output_path" \
--slim \
"${build_args[@]}" \
"$@"

cdroot
Expand Down
2 changes: 1 addition & 1 deletion scripts/coder-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

if [[ ! -x "${CODER_DEV_BIN}" ]]; then
echo "Run this command first:"
echo "go build -o ${CODER_DEV_BIN} ${PROJECT_ROOT}/cmd/coder"
echo "go build -o ${CODER_DEV_BIN} ${PROJECT_ROOT}/enterprise/cmd/coder"
exit 1
fi

Expand Down
31 changes: 30 additions & 1 deletion scripts/develop.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
#!/usr/bin/env bash

# Usage: ./develop.sh [--agpl]
#
# If the --agpl parameter is specified, builds only the AGPL-licensed code (no
# Coder enterprise features).

# Allow toggling verbose output
[[ -n ${VERBOSE:-""} ]] && set -x
set -euo pipefail

agpl="${CODER_BUILD_AGPL:-0}"
args="$(getopt -o "" -l agpl -- "$@")"
eval set -- "$args"
while true; do
case "$1" in
--agpl)
agpl=1
shift
;;
--)
shift
break
;;
*)
error "Unrecognized option: $1"
;;
esac
done

SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
# shellcheck disable=SC1091,SC1090
source "${SCRIPT_DIR}/lib.sh"
Expand All @@ -28,8 +52,13 @@ if [[ ! -e ./site/out/bin/coder.sha1 && ! -e ./site/out/bin/coder.tar.zst ]]; th
exit 1
fi

cmd_path="enterprise/cmd/coder"
if [[ "$agpl" == 1 ]]; then
cmd_path="cmd/coder"
fi

# Compile the CLI binary once just so we don't waste time compiling things multiple times
go build -tags embed -o "${CODER_DEV_BIN}" "${PROJECT_ROOT}/cmd/coder"
go build -tags embed -o "${CODER_DEV_BIN}" "${PROJECT_ROOT}/${cmd_path}"
# Use the coder dev shim so we don't overwrite the user's existing Coder config.
CODER_DEV_SHIM="${PROJECT_ROOT}/scripts/coder-dev.sh"

Expand Down
2 changes: 1 addition & 1 deletion site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const config: PlaywrightTestConfig = {
// Run the coder daemon directly.
command: `go run -tags embed ${path.join(
__dirname,
"../../cmd/coder/main.go",
"../../enterprise/cmd/coder/main.go",
)} server --in-memory`,
port: basePort,
timeout: 120 * 10000,
Expand Down