Skip to content

Commit 7dee23c

Browse files
Adding support to install different go versions in Alpine (#100)
* test: checking if istall fails in alpine * fix: using the correct TAR options for Alpine Linux distro * fix: removing useless cat * fix: removing doulbe quotes from tar options * fix: using bash arrays instead of a string for TAR options * fix: fixing typo * fix: adding curl dependency * fix: given that sh is used in Alpine, we need to remove usage of arrays * fix: updating the condition to prevent issues with sh * fix: adding double quotes * fix: adding -q to grep to silent output * fix: checking result of previous command to test if running in Alpine * fix: fixing check in Alpine using sh * fix: correctly installing go and gofmt to /usr/local/bin * fix: adding double quotes * fix: removing go from /opt/go given that the directory does not exist but /opt does * feat: install go specific version in Alpine by building the binary * fix: adding double quotes to env vars * fix: adding exit condition if cd commands fail * fix: adding command into the if check * fix: remove brackets from test * fix: adding $SUDO in ln commands * fix: adding f to ln to make sure the command does not fail * fix: fix test which was checking for python now it checks for the correct expected version of go * fix: fixing test by removing 1.16 given that this version does not have memstat.gc_sys defined * fix: trying to fix a regression tesdt with caches which is failling now * fix: trying with same version from previous cache * fix: trying to go back to the previous state and behavior of the file * fix: removing previously installed version of go
1 parent b5a5964 commit 7dee23c

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

.circleci/test-deploy.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ jobs:
7070
- run:
7171
name: "Check if the correct python version is accessible & installed"
7272
command: python --version | grep -q "^Python 3.11"
73+
int-test-alpine:
74+
docker:
75+
- image: alpine:latest
76+
steps:
77+
- run: apk add curl
78+
- go/install:
79+
version: 1.17.2
80+
- run:
81+
name: "Check if the correct go version is accessible & installed"
82+
command: go version | grep -q "1.17.2"
7383
int-test-macos-executor:
7484
macos:
7585
xcode: "14.1.0"
@@ -192,6 +202,8 @@ workflows:
192202
filters: *filters
193203
- int-test-cimg-python:
194204
filters: *filters
205+
- int-test-alpine:
206+
filters: *filters
195207
- int-test-macos-executor:
196208
filters: *filters
197209
- int-test-vm-linux:
@@ -220,6 +232,7 @@ workflows:
220232
- int-test-cimg-go
221233
- int-test-cimg-base
222234
- int-test-cimg-python
235+
- int-test-alpine
223236
- int-test-macos-executor
224237
- int-test-vm-linux
225238
- int-test-dirty-cache

src/scripts/install.sh

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
#!/usr/bin/env bash
22

3-
: "${OSD_FAMILY:="linux"}"
4-
: "${HOSTTYPE:="amd64"}"
5-
if [ "${HOSTTYPE}" = "x86_64" ]; then HOSTTYPE="amd64"; fi
6-
if [ "${HOSTTYPE}" = "aarch64" ]; then HOSTTYPE="arm64"; fi
7-
case "${HOSTTYPE}" in *86 ) HOSTTYPE=i386 ;; esac
8-
9-
if command -v go >/dev/null; then
3+
function alpine_install {
4+
cd /opt || exit 200
5+
apk add bash gcc musl-dev go
6+
wget "https://go.dev/dl/go${ORB_VAL_VERSION}.src.tar.gz"
7+
tar xzf "go${ORB_VAL_VERSION}.src.tar.gz"
8+
mv go "go${ORB_VAL_VERSION}"
9+
cd "go${ORB_VAL_VERSION}/src" || exit 201
10+
./make.bash
11+
apk del go
12+
ln -sf "/opt/go${ORB_VAL_VERSION}/bin/go" /usr/local/bin/go
13+
ln -sf "/opt/go${ORB_VAL_VERSION}/bin/gofmt" /usr/local/bin/gofmt
14+
}
15+
16+
function standard_install {
17+
if command -v go >/dev/null; then
1018
if go version | grep -q -F "go<< parameters.version >> "; then
11-
echo "Binary already exists, skipping download."
12-
exit 0
19+
echo "Binary already exists, skipping download."
20+
exit 0
1321
fi
1422

1523
echo "Found a different version of Go."
@@ -18,14 +26,28 @@ if command -v go >/dev/null; then
1826

1927
$SUDO rm -rf /usr/local/go
2028
$SUDO install --owner="${USER}" -d /usr/local/go
21-
fi
29+
$SUDO rm -rf /opt/go
30+
fi
2231

23-
echo "Installing the requested version of Go."
32+
echo "Installing the requested version of Go."
33+
curl -O --fail --location -sS "https://dl.google.com/go/go${ORB_VAL_VERSION}.${OSD_FAMILY}-${HOSTTYPE}.tar.gz"
34+
$SUDO tar xzf "go${ORB_VAL_VERSION}.${OSD_FAMILY}-${HOSTTYPE}.tar.gz" -C /opt
35+
$SUDO rm "go${ORB_VAL_VERSION}.${OSD_FAMILY}-${HOSTTYPE}.tar.gz"
36+
$SUDO ln -sf /opt/go/bin/go /usr/local/bin/go
37+
$SUDO ln -sf /opt/go/bin/gofmt /usr/local/bin/gofmt
2438

25-
curl --fail --location -sS "https://dl.google.com/go/go${ORB_VAL_VERSION}.${OSD_FAMILY}-${HOSTTYPE}.tar.gz" \
26-
| $SUDO tar --no-same-owner --strip-components=1 --gunzip -x -C /usr/local/go/
39+
#shellcheck disable=SC2016
40+
$SUDO chown -R "$(whoami)": /usr/local/bin/go /usr/local/bin/gofmt
41+
}
2742

28-
#shellcheck disable=SC2016
29-
echo 'export PATH=$PATH:/usr/local/go/bin' >> "$BASH_ENV"
30-
$SUDO chown -R "$(whoami)": /usr/local/go
43+
: "${OSD_FAMILY:="linux"}"
44+
: "${HOSTTYPE:="amd64"}"
45+
if [ "${HOSTTYPE}" = "x86_64" ]; then HOSTTYPE="amd64"; fi
46+
if [ "${HOSTTYPE}" = "aarch64" ]; then HOSTTYPE="arm64"; fi
47+
case "${HOSTTYPE}" in *86) HOSTTYPE=i386 ;; esac
3148

49+
if grep alpinelinux /etc/os-release; then
50+
alpine_install
51+
else
52+
standard_install
53+
fi

0 commit comments

Comments
 (0)