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

Skip to content

Commit 067362c

Browse files
authored
feat: add windows amd64 installer (#4719)
1 parent 7d04bf2 commit 067362c

File tree

9 files changed

+473
-4
lines changed

9 files changed

+473
-4
lines changed

.github/workflows/release.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ jobs:
6565
restore-keys: |
6666
js-${{ runner.os }}-
6767
68+
- name: Install nsis and zstd
69+
run: sudo apt-get install -y nsis zstd
70+
6871
- name: Install nfpm
6972
run: |
7073
set -euo pipefail
7174
wget -O /tmp/nfpm.deb https://github.com/goreleaser/nfpm/releases/download/v2.18.1/nfpm_amd64.deb
7275
sudo dpkg -i /tmp/nfpm.deb
73-
- name: Install zstd
74-
run: sudo apt-get install -y zstd
7576
7677
- name: Install rcodesign
7778
run: |
@@ -107,6 +108,7 @@ jobs:
107108
make -j \
108109
build/coder_"$version"_linux_{amd64,armv7,arm64}.{tar.gz,apk,deb,rpm} \
109110
build/coder_"$version"_{darwin,windows}_{amd64,arm64}.zip \
111+
build/coder_"$version"_windows_amd64_installer.exe \
110112
build/coder_helm_"$version".tgz
111113
env:
112114
CODER_SIGN_DARWIN: "1"
@@ -155,6 +157,7 @@ jobs:
155157
run: |
156158
./scripts/publish_release.sh \
157159
${{ (github.event.inputs.dry_run || github.event.inputs.snapshot) && '--dry-run' }} \
160+
./build/*_installer.exe \
158161
./build/*.zip \
159162
./build/*.tar.gz \
160163
./build/*.tgz \

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ $(CODER_ALL_PACKAGES): $(CODER_PACKAGE_DEPS)
252252
--output "$@" \
253253
"build/coder_$(VERSION)_$${os}_$${arch}"
254254

255+
# This task builds a Windows amd64 installer. Depends on makensis.
256+
build/coder_$(VERSION)_windows_amd64_installer.exe: build/coder_$(VERSION)_windows_amd64.exe
257+
./scripts/build_windows_installer.sh \
258+
--version "$(VERSION)" \
259+
--output "$@" \
260+
"$<"
261+
255262
# Redirect from version-less Docker image targets to the versioned ones.
256263
#
257264
# Called like this:

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ Coder creates remote development machines so your team can develop from anywhere
3232
> **Note**:
3333
> Coder is in a beta state. [Report issues here](https://github.com/coder/coder/issues/new).
3434
35-
The easiest way to install Coder is to use our [install script](https://github.com/coder/coder/blob/main/install.sh) for Linux and macOS.
35+
The easiest way to install Coder is to use our
36+
[install script](https://github.com/coder/coder/blob/main/install.sh) for Linux
37+
and macOS. For Windows, use the latest `..._installer.exe` file from GitHub
38+
Releases.
3639

3740
To install, run:
3841

scripts/build_windows_installer.sh

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env bash
2+
3+
# This script packages a Windows installer for Coder containing the given
4+
# binary.
5+
#
6+
# Usage: ./build_windows_installer.sh --output "path/to/installer.exe" [--version 1.2.3] [--agpl] path/to/binary.exe
7+
#
8+
# Only amd64 binaries are supported.
9+
#
10+
# If no version is specified, defaults to the version from ./version.sh.
11+
#
12+
# If the --agpl parameter is specified, only the AGPL license is included in the
13+
# installer.
14+
15+
set -euo pipefail
16+
# shellcheck source=scripts/lib.sh
17+
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
18+
19+
agpl="${CODER_BUILD_AGPL:-0}"
20+
output_path=""
21+
version=""
22+
23+
args="$(getopt -o "" -l agpl,output:,version: -- "$@")"
24+
eval set -- "$args"
25+
while true; do
26+
case "$1" in
27+
--agpl)
28+
agpl=1
29+
shift
30+
;;
31+
--output)
32+
mkdir -p "$(dirname "$2")"
33+
output_path="$(realpath "$2")"
34+
shift 2
35+
;;
36+
--version)
37+
version="$2"
38+
shift 2
39+
;;
40+
--)
41+
shift
42+
break
43+
;;
44+
*)
45+
error "Unrecognized option: $1"
46+
;;
47+
esac
48+
done
49+
50+
if [[ "$output_path" == "" ]]; then
51+
error "--output is a required parameter"
52+
fi
53+
54+
if [[ "$#" != 1 ]]; then
55+
error "Exactly one argument must be provided to this script, $# were supplied"
56+
fi
57+
if [[ ! -f "$1" ]]; then
58+
error "File '$1' does not exist or is not a regular file"
59+
fi
60+
input_file="$(realpath "$1")"
61+
62+
version="${version#v}"
63+
if [[ "$version" == "" ]]; then
64+
version="$(execrelative ./version.sh)"
65+
fi
66+
67+
# Remove the "v" prefix and ensure the version is in the format X.X.X.X for
68+
# makensis.
69+
nsis_version="${version//-*/}"
70+
nsis_version+=".$(date -u +%Y%m%d%H%M)"
71+
72+
# Check dependencies
73+
dependencies makensis
74+
75+
# Make a temporary dir where all source files intended to be in the installer
76+
# will be hardlinked/copied to.
77+
cdroot
78+
temp_dir="$(TMPDIR="$(dirname "$input_file")" mktemp -d)"
79+
mkdir -p "$temp_dir/bin"
80+
ln "$input_file" "$temp_dir/bin/coder.exe"
81+
cp "$(realpath scripts/win-installer/installer.nsi)" "$temp_dir/installer.nsi"
82+
cp "$(realpath scripts/win-installer/path.nsh)" "$temp_dir/path.nsh"
83+
cp "$(realpath scripts/win-installer/coder.ico)" "$temp_dir/coder.ico"
84+
cp "$(realpath scripts/win-installer/banner.bmp)" "$temp_dir/banner.bmp"
85+
86+
# Craft a license document by combining the AGPL license and optionally the
87+
# enterprise license.
88+
license_path="$temp_dir/license.txt"
89+
90+
if [[ "$agpl" == 0 ]]; then
91+
cat <<-EOF >"$license_path"
92+
This distribution of Coder includes some enterprise-licensed code which is not
93+
licensed under the AGPL license:
94+
95+
$(sed 's/^/ /' "$(realpath LICENSE.enterprise)")
96+
97+
98+
99+
The non-enterprise code in this distribution is licensed under the AGPL license:
100+
101+
$(sed 's/^/ /' "$(realpath LICENSE)")
102+
EOF
103+
else
104+
cat <<-EOF >"$license_path"
105+
This distribution of Coder is free software and is licensed under the AGPL
106+
license:
107+
108+
$(sed 's/^/ /' "$(realpath LICENSE)")
109+
EOF
110+
fi
111+
112+
# Run makensis to build the installer.
113+
pushd "$temp_dir"
114+
makensis \
115+
-V4 \
116+
-DCODER_VERSION="$version" \
117+
-DCODER_NSIS_VERSION="$nsis_version" \
118+
-DCODER_YEAR="$(date +%Y)" \
119+
installer.nsi
120+
popd
121+
122+
# Copy the installer to the output path.
123+
cp "$temp_dir/installer.exe" "$output_path"
124+
125+
rm -rf "$temp_dir"

scripts/package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if [[ "$arch" == "arm" ]] || [[ "$arch" == "armv7" ]]; then
7979
fi
8080

8181
# Make temporary dir where all source files intended to be in the package will
82-
# be hardlinked from.
82+
# be hardlinked to.
8383
cdroot
8484
temp_dir="$(TMPDIR="$(dirname "$input_file")" mktemp -d)"
8585
ln "$input_file" "$temp_dir/coder"

scripts/win-installer/banner.bmp

151 KB
Binary file not shown.

scripts/win-installer/coder.ico

422 KB
Binary file not shown.

scripts/win-installer/installer.nsi

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# This NSIS installer script was taken from the following webpage and heavily
2+
# adapted to Coder's needs:
3+
# https://www.conjur.org/blog/building-a-windows-installer-from-a-linux-ci-pipeline/
4+
5+
Unicode true
6+
7+
!define APP_NAME "Coder"
8+
!define COMP_NAME "Coder Technologies, Inc."
9+
!define VERSION "${CODER_NSIS_VERSION}"
10+
!define COPYRIGHT "Copyright (c) ${CODER_YEAR} Coder Technologies, Inc."
11+
!define DESCRIPTION "Remote development environments on your infrastructure provisioned with Terraform"
12+
!define INSTALLER_NAME "installer.exe"
13+
!define MAIN_APP_EXE "coder.exe"
14+
!define MAIN_APP_EXE_PATH "bin\coder.exe"
15+
!define ICON "coder.ico"
16+
!define BANNER "banner.bmp"
17+
!define LICENSE_TXT "license.txt"
18+
19+
!define INSTALL_DIR "$PROGRAMFILES64\${APP_NAME}"
20+
!define INSTALL_TYPE "SetShellVarContext all" # this means install for all users
21+
!define REG_ROOT "HKLM"
22+
!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${MAIN_APP_EXE}"
23+
!define UNINSTALL_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"
24+
25+
######################################################################
26+
27+
VIProductVersion "${VERSION}"
28+
VIAddVersionKey "ProductName" "${APP_NAME}"
29+
VIAddVersionKey "CompanyName" "${COMP_NAME}"
30+
VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
31+
VIAddVersionKey "FileDescription" "${DESCRIPTION}"
32+
VIAddVersionKey "FileVersion" "${VERSION}"
33+
34+
######################################################################
35+
36+
SetCompressor /SOLID Lzma
37+
Name "${APP_NAME}"
38+
Caption "${APP_NAME}"
39+
OutFile "${INSTALLER_NAME}"
40+
BrandingText "${APP_NAME} v${CODER_VERSION}"
41+
InstallDirRegKey "${REG_ROOT}" "${REG_APP_PATH}" "Path"
42+
InstallDir "${INSTALL_DIR}"
43+
44+
######################################################################
45+
46+
!define MUI_ICON "${ICON}"
47+
!define MUI_UNICON "${ICON}"
48+
!define MUI_WELCOMEFINISHPAGE_BITMAP "${BANNER}"
49+
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${BANNER}"
50+
51+
######################################################################
52+
53+
!include "MUI2.nsh"
54+
55+
!define MUI_ABORTWARNING
56+
!define MUI_UNABORTWARNING
57+
58+
!define MUI_WELCOMEPAGE_TEXT "Setup will guide you through the installation of Coder v${CODER_VERSION}.$\r$\n$\r$\nClick Next to continue."
59+
60+
!insertmacro MUI_PAGE_WELCOME
61+
62+
!insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}"
63+
64+
!insertmacro MUI_PAGE_COMPONENTS
65+
66+
!insertmacro MUI_PAGE_DIRECTORY
67+
68+
!insertmacro MUI_PAGE_INSTFILES
69+
70+
!define MUI_FINISHPAGE_TEXT "Coder v${CODER_VERSION} has been installed on your computer.$\r$\n$\r$\nIf you added Coder to your PATH, you can use Coder by opening a command prompt or PowerShell and running `coder`. You may have to sign out and sign back in for `coder` to be available.$\r$\n$\r$\nClick Finish to close Setup."
71+
72+
!insertmacro MUI_PAGE_FINISH
73+
74+
!insertmacro MUI_UNPAGE_CONFIRM
75+
76+
!insertmacro MUI_UNPAGE_INSTFILES
77+
78+
!insertmacro MUI_UNPAGE_FINISH
79+
80+
!insertmacro MUI_LANGUAGE "English"
81+
82+
######################################################################
83+
84+
!include ".\path.nsh"
85+
86+
Section "Coder CLI" SecInstall
87+
SectionIn RO # mark this section as required
88+
89+
${INSTALL_TYPE}
90+
91+
SetOverwrite ifnewer
92+
SetOutPath "$INSTDIR"
93+
File /r "bin"
94+
File "${LICENSE_TXT}"
95+
96+
WriteUninstaller "$INSTDIR\uninstall.exe"
97+
98+
WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE_PATH}"
99+
WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "Path" "$INSTDIR"
100+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
101+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
102+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE_PATH}"
103+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}"
104+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}"
105+
SectionEnd
106+
107+
Section "Add to PATH" SecAddToPath
108+
Push "$INSTDIR\bin"
109+
Call AddToPath
110+
SectionEnd
111+
112+
######################################################################
113+
114+
Section Uninstall
115+
${INSTALL_TYPE}
116+
117+
RmDir /r "$INSTDIR"
118+
DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
119+
DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
120+
121+
Push "$INSTDIR\bin"
122+
Call un.RemoveFromPath
123+
SectionEnd
124+
125+
######################################################################
126+
127+
LangString DESC_SecInstall ${LANG_ENGLISH} "Install the Coder command-line interface (coder.exe) for all users."
128+
LangString DESC_SecAddToPath ${LANG_ENGLISH} "Add coder.exe to the PATH for all users. This enables `coder` to be used directly from a command prompt or PowerShell."
129+
130+
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
131+
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
132+
!insertmacro MUI_DESCRIPTION_TEXT ${SecAddToPath} $(DESC_SecAddToPath)
133+
!insertmacro MUI_FUNCTION_DESCRIPTION_END

0 commit comments

Comments
 (0)