From f541b3b3f2570a9daca7531c9112498b1f4ebb03 Mon Sep 17 00:00:00 2001 From: recanman <29310982+recanman@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:06:30 -0700 Subject: [PATCH 1/2] fix: install openrc service on alpine (#12294) --- scripts/linux-pkg/coder-openrc | 38 ++++++++++++++++++ .../linux-pkg/coder-workspace-proxy-openrc | 39 +++++++++++++++++++ scripts/linux-pkg/nfpm-alpine.yaml | 29 ++++++++++++++ scripts/package.sh | 9 ++++- 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100755 scripts/linux-pkg/coder-openrc create mode 100755 scripts/linux-pkg/coder-workspace-proxy-openrc create mode 100644 scripts/linux-pkg/nfpm-alpine.yaml diff --git a/scripts/linux-pkg/coder-openrc b/scripts/linux-pkg/coder-openrc new file mode 100755 index 0000000000000..d7b5800f05c44 --- /dev/null +++ b/scripts/linux-pkg/coder-openrc @@ -0,0 +1,38 @@ +#!/sbin/openrc-run +name=coder +description="Coder - Self-hosted developer workspaces on your infra" +document="https://coder.com/docs/coder-oss" + +depend() { + need net + after net-online + use dns logger +} + +checkpath --directory --owner coder:coder --mode 0700 /var/cache/coder + +start_pre() { + if [ ! -f /etc/coder.d/coder.env ]; then + eerror "/etc/coder.d/coder.env file does not exist" + return 1 + fi + # Read and export environment variables ignoring comment lines and blank lines + while IFS= read -r line; do + # Skip blank or comment lines + if [ -z "$line" ] || [[ "$line" =~ ^# ]]; then + continue + fi + export "$line" + done < /etc/coder.d/coder.env +} + +command="/usr/bin/coder" +command_args="server" +command_user="coder:coder" +command_background="yes" +pidfile="/run/coder.pid" + +restart="always" +restart_delay="5" + +stop_timeout="90" diff --git a/scripts/linux-pkg/coder-workspace-proxy-openrc b/scripts/linux-pkg/coder-workspace-proxy-openrc new file mode 100755 index 0000000000000..867812f4bd66e --- /dev/null +++ b/scripts/linux-pkg/coder-workspace-proxy-openrc @@ -0,0 +1,39 @@ +#!/sbin/openrc-run +name=coder-workspace-proxy +description="Coder - external workspace proxy server" +document="https://coder.com/docs/coder-oss" + +depend() { + need net + after net-online + use dns logger +} + +checkpath --directory --owner coder:coder --mode 0700 /var/cache/coder + +start_pre() { + if [ ! -f /etc/coder.d/coder-workspace-proxy.env ]; then + eerror "/etc/coder.d/coder-workspace-proxy.env file does not exist" + return 1 + fi + + # Read and export environment variables ignoring comment lines and blank lines + while IFS= read -r line; do + # Skip blank or comment lines + if [ -z "$line" ] || [[ "$line" =~ ^# ]]; then + continue + fi + export "$line" + done < /etc/coder.d/coder-workspace-proxy.env +} + +command="/usr/bin/coder" +command_args="workspace-proxy server" +command_user="coder:coder" +command_background="yes" +pidfile="/run/coder-workspace-proxy.pid" + +restart="always" +restart_delay="5" + +stop_timeout="90" diff --git a/scripts/linux-pkg/nfpm-alpine.yaml b/scripts/linux-pkg/nfpm-alpine.yaml new file mode 100644 index 0000000000000..dbf885fed10ba --- /dev/null +++ b/scripts/linux-pkg/nfpm-alpine.yaml @@ -0,0 +1,29 @@ +name: coder +platform: linux +arch: "${GOARCH}" +version: "${CODER_VERSION}" +version_schema: semver +release: 1 + +vendor: Coder +homepage: https://coder.com +maintainer: Coder +description: | + Provision development environments with infrastructure with code +license: AGPL-3.0 +suggests: + - postgresql + +scripts: + preinstall: preinstall.sh + +contents: + - src: coder + dst: /usr/bin/coder + - src: coder.env + dst: /etc/coder.d/coder.env + type: "config|noreplace" + - src: coder-workspace-proxy-openrc + dst: /etc/init.d/coder-workspace-proxy + - src: coder-openrc + dst: /etc/init.d/coder diff --git a/scripts/package.sh b/scripts/package.sh index 8afbf5d608ea9..a02a40eb3ff32 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -89,9 +89,16 @@ ln "$(realpath scripts/linux-pkg/coder.service)" "$temp_dir/" ln "$(realpath scripts/linux-pkg/nfpm.yaml)" "$temp_dir/" ln "$(realpath scripts/linux-pkg/preinstall.sh)" "$temp_dir/" +nfpm_config_file="nfpm.yaml" + +# Use nfpm-alpine.yaml when building for Alpine (OpenRC). +if [[ "$format" == "apk" ]]; then + nfpm_config_file="nfpm-alpine.yaml" +fi + pushd "$temp_dir" GOARCH="$arch" CODER_VERSION="$version" nfpm package \ - -f nfpm.yaml \ + -f "$nfpm_config_file" \ -p "$format" \ -t "$output_path" \ 1>&2 From 294fb31d70e760f2c9aaf74dbf6a93d7ea57baca Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 3 May 2024 21:01:10 +0000 Subject: [PATCH 2/2] fmt --- scripts/linux-pkg/nfpm-alpine.yaml | 24 ++++++++++++------------ scripts/package.sh | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/linux-pkg/nfpm-alpine.yaml b/scripts/linux-pkg/nfpm-alpine.yaml index dbf885fed10ba..ab174a6c873bd 100644 --- a/scripts/linux-pkg/nfpm-alpine.yaml +++ b/scripts/linux-pkg/nfpm-alpine.yaml @@ -9,21 +9,21 @@ vendor: Coder homepage: https://coder.com maintainer: Coder description: | - Provision development environments with infrastructure with code + Provision development environments with infrastructure with code license: AGPL-3.0 suggests: - - postgresql + - postgresql scripts: - preinstall: preinstall.sh + preinstall: preinstall.sh contents: - - src: coder - dst: /usr/bin/coder - - src: coder.env - dst: /etc/coder.d/coder.env - type: "config|noreplace" - - src: coder-workspace-proxy-openrc - dst: /etc/init.d/coder-workspace-proxy - - src: coder-openrc - dst: /etc/init.d/coder + - src: coder + dst: /usr/bin/coder + - src: coder.env + dst: /etc/coder.d/coder.env + type: "config|noreplace" + - src: coder-workspace-proxy-openrc + dst: /etc/init.d/coder-workspace-proxy + - src: coder-openrc + dst: /etc/init.d/coder diff --git a/scripts/package.sh b/scripts/package.sh index a02a40eb3ff32..2b826735f38ce 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -93,7 +93,7 @@ nfpm_config_file="nfpm.yaml" # Use nfpm-alpine.yaml when building for Alpine (OpenRC). if [[ "$format" == "apk" ]]; then - nfpm_config_file="nfpm-alpine.yaml" + nfpm_config_file="nfpm-alpine.yaml" fi pushd "$temp_dir"