Skip to content

Commit c3c44ae

Browse files
committed
We should avoid setting GO env variables
It should be enough to temporarily set GOPATH during docker image build to install tools in a shared directory and then add that directory to $PATH. The defaults on linux are: GOPATH = ~/go GOROOT = /usr/local/go GOMODCACHE = GOPATH[0]/pkg/mod
1 parent 1ab3d9e commit c3c44ae

File tree

7 files changed

+24
-38
lines changed

7 files changed

+24
-38
lines changed

.containerversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
28
1+
29

Dockerfile

+7-11
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
FROM thyrlian/android-sdk:4.0 as android
14+
FROM thyrlian/android-sdk:4.0 AS android
1515

1616
FROM ubuntu:22.04
1717

18-
ENV DEBIAN_FRONTEND noninteractive
19-
2018
# Android
2119
COPY --from=android /opt/android-sdk /opt/android-sdk
2220

23-
ADD scripts/docker_install.sh /tmp/
24-
RUN /tmp/docker_install.sh
21+
RUN --mount=target=/mnt,source=scripts DEBIAN_FRONTEND=noninteractive /mnt/docker_install.sh
2522

26-
ENV GOPATH /opt/go
27-
ENV GOROOT /opt/go_dist/go
28-
ENV PATH $GOROOT/bin:$GOPATH/bin:$PATH
23+
# In this path executables will be installed during docker build
24+
ARG SYS_GOPATH=/opt/go
25+
ENV PATH=${SYS_GOPATH}/bin:/usr/local/go/bin:$PATH
2926

30-
ADD Makefile /tmp/
31-
RUN make -C /tmp/ envinit
27+
RUN --mount=target=/mnt/Makefile,source=Makefile GOPATH=${SYS_GOPATH} make -C /mnt envinit
3228

33-
ENV PATH /opt/qt6/6.8.2/gcc_64/bin:/opt/qt6/6.8.2/gcc_64/libexec:$PATH
29+
ENV PATH=/opt/qt6/6.8.2/gcc_64/bin:/opt/qt6/6.8.2/gcc_64/libexec:$PATH
3430

3531
CMD ["bash"]

Makefile

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414

1515
SHELL := /bin/bash
1616
WEBROOT := frontends/web
17-
GOPATH ?= $(HOME)/go
18-
PATH := $(PATH):$(GOPATH)/bin
1917

2018
catch:
2119
@echo "Choose a make target."
2220
envinit:
2321
# Keep golangci-lint version in sync with what's in .github/workflows/ci.yml.
24-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.61.0
22+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.61.0
2523
go install github.com/vektra/mockery/[email protected]
2624
go install github.com/matryer/[email protected]
2725
go install golang.org/x/tools/cmd/goimports@latest
@@ -84,8 +82,11 @@ clean:
8482
cd frontends/qt && $(MAKE) clean
8583
cd frontends/android && $(MAKE) clean
8684
cd backend/mobileserver && $(MAKE) clean
85+
86+
# The container image only supports amd64 bercause of "thyrlian/android-sdk"
87+
# that downloads amd64 specific binaries
8788
dockerinit:
88-
./scripts/container.sh build --pull --force-rm -t shiftcrypto/bitbox-wallet-app .
89+
./scripts/container.sh build --platform linux/amd64 --pull -t shiftcrypto/bitbox-wallet-app:$(shell cat .containerversion) .
8990
dockerdev:
9091
./scripts/dockerdev.sh
9192
locize-push:

android-env.mk.inc

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
export ANDROID_SDK_ROOT := /opt/android-sdk
22
export ANDROID_NDK_HOME := /opt/android-sdk/ndk/21.2.6472646
3-
# gomodcache location for gomobile build pkgs. Set to tmp folder, because writing access is needed.
4-
export GOMODCACHE_ROOT := /tmp/gomodcache/pkg/mod

backend/mobileserver/Makefile

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
include ../../android-env.mk.inc
22

3-
# GOMODCACHE to /tmp directory, because gomobile needs to write pkgs.
4-
# Also set -glflags to fix the vendor issue with gomobile, see: https://github.com/golang/go/issues/67927#issuecomment-2241523694
3+
# Set -glflags to fix the vendor issue with gomobile, see: https://github.com/golang/go/issues/67927#issuecomment-2241523694
54
build-android:
6-
GOMODCACHE=${GOMODCACHE_ROOT} ANDROID_HOME=${ANDROID_SDK_ROOT} gomobile bind -x -a -glflags="-mod=readonly" -ldflags="-s -w" -target android .
5+
ANDROID_HOME=${ANDROID_SDK_ROOT} gomobile bind -x -a -glflags="-mod=readonly" -ldflags="-s -w" -target android .
76
build-ios:
8-
GOMODCACHE=${GOMODCACHE_ROOT} gomobile bind -x -a -glflags="-mod=readonly" -ldflags="-s -w" -target ios,iossimulator .
7+
gomobile bind -x -a -glflags="-mod=readonly" -ldflags="-s -w" -target ios,iossimulator .
98
clean:
109
rm -f mobileserver.aar mobileserver-sources.jar

scripts/docker_install.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
1716
apt-get update
1817
apt-get install -y --no-install-recommends curl ca-certificates
1918

@@ -83,8 +82,7 @@ aqt install-qt linux desktop 6.8.2 -m qtpositioning qtserialport qtwebchannel qt
8382
npm install -g npm@10
8483
npm install -g locize-cli
8584

86-
mkdir -p /opt/go_dist
87-
curl https://dl.google.com/go/go1.22.5.linux-amd64.tar.gz | tar -xz -C /opt/go_dist
85+
curl https://dl.google.com/go/go1.22.5.linux-amd64.tar.gz | tar -xz -C /usr/local
8886

8987
# fuse is needed to run the linuxdeployqt appimage.
9088
apt-get install -y --no-install-recommends fuse

scripts/github-ci.sh

+7-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if [ "$OS_NAME" == "linux" ]; then
1212
# Which docker image to use to run the CI. Defaults to Docker Hub.
1313
# Overwrite with CI_IMAGE=docker/image/path environment variable.
1414
# Keep this in sync with .github/workflows/ci.yml.
15-
: "${CI_IMAGE:=shiftcrypto/bitbox-wallet-app:26}"
15+
: "${CI_IMAGE:=shiftcrypto/bitbox-wallet-app:$(cat .containerversion)}"
1616
# Time image pull to compare in the future.
1717
time docker pull "$CI_IMAGE"
1818

@@ -22,24 +22,18 @@ if [ "$OS_NAME" == "linux" ]; then
2222
# CI (https://github.com/actions/checkout/issues/760)
2323
docker run --privileged \
2424
-v $HOME/.gradle:/root/.gradle \
25-
-v ${GITHUB_BUILD_DIR}:/opt/go/${GO_SRC_DIR}/ \
25+
-v ${GITHUB_BUILD_DIR}:/root/go/${GO_SRC_DIR}/ \
2626
-i "${CI_IMAGE}" \
27-
bash -c "git config --global --add safe.directory \$GOPATH/${GO_SRC_DIR} && make -C \$GOPATH/${GO_SRC_DIR} ${WHAT}"
27+
bash -c "git config --global --add safe.directory \$(go env GOPATH)/${GO_SRC_DIR} && make -C \$(go env GOPATH)/${GO_SRC_DIR} ${WHAT}"
2828
fi
2929

3030
# The following is executed only on macOS machines.
3131
if [ "$OS_NAME" == "osx" ]; then
3232
# GitHub CI installs Go and Qt directly in the macos action, before executing
3333
# this script.
3434
go version
35-
export GOPATH=~/go
36-
export PATH="$PATH:~/go/bin"
37-
mkdir -p $GOPATH/$(dirname $GO_SRC_DIR)
38-
# GitHub checkout action (git clone) seem to require current work dir
39-
# to be the root of the repo during its clean up phase. So, we push it
40-
# here and pop in the end.
41-
pushd ../ && cp -a bitbox-wallet-app $GOPATH/$(dirname $GO_SRC_DIR)
42-
cd $GOPATH/$GO_SRC_DIR
43-
make "$WHAT"
44-
popd
35+
export PATH="~/go/bin:$PATH"
36+
mkdir -p $(go env GOPATH)/$(dirname $GO_SRC_DIR)
37+
cp -a ../bitbox-wallet-app $(go env GOPATH)/$(dirname $GO_SRC_DIR)
38+
make -C $(go env GOPATH)/$GO_SRC_DIR "$WHAT"
4539
fi

0 commit comments

Comments
 (0)