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

Skip to content

Commit 1ae6c47

Browse files
committed
feat: add windows installer
1 parent bf3224e commit 1ae6c47

File tree

8 files changed

+446
-1
lines changed

8 files changed

+446
-1
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ jobs:
107107
make -j \
108108
build/coder_"$version"_linux_{amd64,armv7,arm64}.{tar.gz,apk,deb,rpm} \
109109
build/coder_"$version"_{darwin,windows}_{amd64,arm64}.zip \
110+
build/coder_"$version"_windows_amd64_installer.exe \
110111
build/coder_helm_"$version".tgz
111112
env:
112113
CODER_SIGN_DARWIN: "1"
@@ -155,6 +156,7 @@ jobs:
155156
run: |
156157
./scripts/publish_release.sh \
157158
${{ (github.event.inputs.dry_run || github.event.inputs.snapshot) && '--dry-run' }} \
159+
./build/*_installer.exe \
158160
./build/*.zip \
159161
./build/*.tar.gz \
160162
./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:

scripts/build_windows_installer.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
# Remove the "v" prefix and ensure the version is in the format X.X.X.X for
63+
# makensis.
64+
version="${version#v}"
65+
if [[ "$version" == "" ]]; then
66+
version="$(execrelative ./version.sh)"
67+
fi
68+
version="$(echo "$version" | sed 's/-.*//')"
69+
version+=".$(date -u +%Y%m%d%H%M)"
70+
71+
# Check dependencies
72+
dependencies makensis
73+
74+
# Make a temporary dir where all source files intended to be in the installer
75+
# will be hardlinked/copied to.
76+
cdroot
77+
temp_dir="$(TMPDIR="$(dirname "$input_file")" mktemp -d)"
78+
mkdir -p "$temp_dir/bin"
79+
ln "$input_file" "$temp_dir/bin/coder.exe"
80+
cp "$(realpath scripts/installer/installer.nsi)" "$temp_dir/installer.nsi"
81+
cp "$(realpath scripts/installer/path.nsh)" "$temp_dir/path.nsh"
82+
cp "$(realpath scripts/installer/coder.ico)" "$temp_dir/coder.ico"
83+
cp "$(realpath scripts/installer/banner.bmp)" "$temp_dir/banner.bmp"
84+
85+
# Craft a license document by combining the AGPL license and optionally the
86+
# enterprise license.
87+
license_path="$temp_dir/license.txt"
88+
89+
if [[ "$agpl" == 0 ]]; then
90+
cat <<- EOF > "$license_path"
91+
This distribution of Coder includes some enterprise-licensed code which is not
92+
licensed under the AGPL license:
93+
94+
$(cat "$(realpath LICENSE.enterprise)" | sed 's/^/ /')
95+
96+
97+
98+
The non-enterprise code in this distribution is licensed under the AGPL license:
99+
100+
$(cat "$(realpath LICENSE)" | sed 's/^/ /')
101+
EOF
102+
else
103+
cat <<- EOF > "$license_path"
104+
This distribution of Coder is free software and is licensed under the AGPL
105+
license:
106+
107+
$(cat "$(realpath LICENSE)" | sed 's/^/ /')
108+
EOF
109+
fi
110+
111+
# Run makensis to build the installer.
112+
pushd "$temp_dir"
113+
makensis \
114+
-V4 \
115+
-DCODER_VERSION="$version" \
116+
-DCODER_YEAR="$(date +%Y)" \
117+
installer.nsi
118+
popd
119+
120+
# Copy the installer to the output path.
121+
cp "$temp_dir/installer.exe" "$output_path"
122+
123+
rm -rf "$temp_dir"

scripts/installer/banner.bmp

151 KB
Binary file not shown.

scripts/installer/coder.ico

422 KB
Binary file not shown.

scripts/installer/installer.nsi

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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_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}"
41+
InstallDirRegKey "${REG_ROOT}" "${REG_APP_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+
!insertmacro MUI_PAGE_WELCOME
59+
60+
!insertmacro MUI_PAGE_LICENSE "${LICENSE_TXT}"
61+
62+
!insertmacro MUI_PAGE_COMPONENTS
63+
64+
!insertmacro MUI_PAGE_DIRECTORY
65+
66+
!insertmacro MUI_PAGE_INSTFILES
67+
68+
!define MUI_FINISHPAGE_TEXT "Coder has been installed on your computer.$\r$\n$\r$\nTo use Coder, sign out and back in, then open a command prompt or PowerShell and run `coder`.$\r$\n$\r$\nClick Finish to close Setup."
69+
70+
!insertmacro MUI_PAGE_FINISH
71+
72+
!insertmacro MUI_UNPAGE_CONFIRM
73+
74+
!insertmacro MUI_UNPAGE_INSTFILES
75+
76+
!insertmacro MUI_UNPAGE_FINISH
77+
78+
!insertmacro MUI_LANGUAGE "English"
79+
80+
######################################################################
81+
82+
!include ".\path.nsh"
83+
84+
Section "Coder CLI" SecInstall
85+
SectionIn RO # mark this section as required
86+
87+
${INSTALL_TYPE}
88+
89+
SetOverwrite ifnewer
90+
SetOutPath "$INSTDIR"
91+
File /r "bin"
92+
File "${LICENSE_TXT}"
93+
94+
WriteUninstaller "$INSTDIR\uninstall.exe"
95+
96+
WriteRegStr ${REG_ROOT} "${REG_APP_PATH}" "" "$INSTDIR\${MAIN_APP_EXE_PATH}"
97+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayName" "${APP_NAME}"
98+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "UninstallString" "$INSTDIR\uninstall.exe"
99+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayIcon" "$INSTDIR\${MAIN_APP_EXE_PATH}"
100+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "DisplayVersion" "${VERSION}"
101+
WriteRegStr ${REG_ROOT} "${UNINSTALL_PATH}" "Publisher" "${COMP_NAME}"
102+
SectionEnd
103+
104+
Section "Add to PATH" SecAddToPath
105+
Push "$INSTDIR\bin"
106+
Call AddToPath
107+
SectionEnd
108+
109+
######################################################################
110+
111+
Section Uninstall
112+
${INSTALL_TYPE}
113+
114+
RmDir /r "$INSTDIR"
115+
DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}"
116+
DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}"
117+
118+
Push "$INSTDIR\bin"
119+
Call un.RemoveFromPath
120+
SectionEnd
121+
122+
######################################################################
123+
124+
LangString DESC_SecInstall ${LANG_ENGLISH} "Install the Coder command-line interface (coder.exe) for all users."
125+
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."
126+
127+
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
128+
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
129+
!insertmacro MUI_DESCRIPTION_TEXT ${SecAddToPath} $(DESC_SecAddToPath)
130+
!insertmacro MUI_FUNCTION_DESCRIPTION_END

0 commit comments

Comments
 (0)