Skip to content

Commit e1e7855

Browse files
authored
Merge pull request #158 from lightninglabs/docker-arm
docker: refactor build process to support building ARM images
2 parents f0be051 + 953b0cb commit e1e7855

33 files changed

+84180
-66
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Instruct the GitHub linguist tool to interpret the generated JS code as just
2+
# that, generated. This will make sure the JS (and TS types for that matter)
3+
# will not show up in the repository's language statistics.
4+
5+
app/src/types/generated* linguist-generated

.github/workflows/docker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
uses: docker/build-push-action@v2
3939
with:
4040
push: true
41+
platforms: linux/amd64,linux/arm/v7,linux/arm64
4142
tags: "${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}"
4243
build-args: checkout=${{ env.RELEASE_VERSION }}
4344

.github/workflows/main.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches:
99
- "*"
1010

11+
env:
12+
# go needs absolute directories, using the $HOME variable doesn't work here.
13+
DOWNLOAD_CACHE: /home/runner/work/download_cache
14+
1115
jobs:
1216
frontend:
1317
name: frontend tests on ${{ matrix.os }}
@@ -118,3 +122,54 @@ jobs:
118122

119123
- name: build backend binary
120124
run: make build
125+
126+
proto-compile-check:
127+
name: RPC proto compilation check
128+
runs-on: ubuntu-latest
129+
steps:
130+
- name: set git config
131+
run: |
132+
git config --global core.eol lf
133+
git config --global core.autocrlf false
134+
135+
- name: git checkout
136+
uses: actions/checkout@v2
137+
138+
- name: setup nodejs v${{ matrix.node_version }}
139+
uses: actions/setup-node@v1
140+
with:
141+
node-version: 12.x
142+
143+
- name: download cache
144+
uses: actions/cache@v1
145+
with:
146+
path: /home/runner/work/download_cache
147+
key: lnd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }}
148+
restore-keys: |
149+
lnd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }}
150+
lnd-${{ runner.os }}-download-
151+
152+
- name: install protoc and protobuf libraries
153+
run: ./scripts/install_protoc.sh
154+
155+
- name: get yarn cache dir
156+
id: yarn-cache-dir
157+
run: echo "::set-output name=dir::$(yarn cache dir)"
158+
159+
- name: yarn cache
160+
uses: actions/cache@v2
161+
id: yarn-cache
162+
with:
163+
path: ${{ steps.yarn-cache-dir.outputs.dir }}
164+
key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
165+
restore-keys: |
166+
${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
167+
${{ runner.os }}-yarn-${{ matrix.node_version }}-
168+
${{ runner.os }}-yarn-
169+
170+
- name: install dependencies
171+
working-directory: ./app
172+
run: yarn
173+
174+
- name: run check
175+
run: make protos-check

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# generated proto scripts
2-
/app/src/types/generated
3-
41
# local environment vars to ignore
52
.env*.local
63

Dockerfile

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,54 @@
1-
FROM golang:1.15.5-alpine as builder
2-
3-
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
4-
# queries required to connect to linked containers succeed.
5-
ENV GODEBUG netdns=cgo
1+
# Start with a NodeJS base image that also contains yarn.
2+
FROM node:12.17.0-alpine as nodejsbuilder
63

74
# Pass a tag, branch or a commit using build-arg. This allows a docker image to
85
# be built from a specified Git state. The default image will use the Git tip of
96
# master by default.
107
ARG checkout="master"
118

12-
# Explicitly turn on the use of modules (until this becomes the default).
13-
ENV GO111MODULE on
9+
# There seem to be multiple problems when using yarn for a build inside of a
10+
# docker image:
11+
# 1. For building and installing node-gyp, python is required. This seems to
12+
# be missing from the NodeJS base image for ARM builds (or is just required
13+
# when building for ARM?).
14+
# 2. Because of a problem in the docker internal network on ARM, some TCP
15+
# packages are being dropped and the yarn installation times out. This can
16+
# be mitigated by switching to HTTP and increasing the network timeout.
17+
# See https://github.com/yarnpkg/yarn/issues/5259 for more info.
18+
RUN apk add --no-cache --update alpine-sdk \
19+
python \
20+
git \
21+
&& git clone https://github.com/lightninglabs/lightning-terminal /go/src/github.com/lightninglabs/lightning-terminal \
22+
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
23+
&& git checkout $checkout \
24+
&& cd app \
25+
&& npm config set registry "http://registry.npmjs.org" \
26+
&& yarn config set registry "http://registry.npmjs.org" \
27+
&& yarn install --frozen-lockfile --network-timeout 1000000 \
28+
&& yarn build
1429

15-
ENV NODE_VERSION=v12.17.0
30+
# The first stage is already done and all static assets should now be generated
31+
# in the app/build sub directory.
32+
FROM golang:1.15.5-alpine as golangbuilder
1633

17-
# We need some additional proto files with google annotations, the version
18-
# should match what's in lnd's scripts/install_travis_proto.sh
19-
ENV PROTOC_VERSION=3.4.0
20-
ENV PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip"
34+
# Instead of checking out from git again, we just copy the whole working
35+
# directory of the previous stage that includes the generated static assets.
36+
COPY --from=nodejsbuilder /go/src/github.com/lightninglabs/lightning-terminal /go/src/github.com/lightninglabs/lightning-terminal
37+
38+
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
39+
# queries required to connect to linked containers succeed.
40+
ENV GODEBUG netdns=cgo
41+
42+
# Explicitly turn on the use of modules (until this becomes the default).
43+
ENV GO111MODULE on
2144

2245
# Install dependencies and install/build lightning-terminal.
2346
RUN apk add --no-cache --update alpine-sdk \
24-
git \
2547
make \
26-
curl \
27-
bash \
28-
binutils \
29-
tar \
30-
protobuf-dev \
31-
zip \
32-
&& curl -sfSLO ${PROTOC_URL} \
33-
&& unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local \
34-
&& rm /usr/local/bin/protoc /usr/local/readme.txt \
35-
&& touch ~/.bashrc \
36-
&& curl -sfSLO https://unofficial-builds.nodejs.org/download/release/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64-musl.tar.xz \
37-
&& tar -xf node-${NODE_VERSION}-linux-x64-musl.tar.xz -C /usr --strip 1 \
38-
&& rm node-${NODE_VERSION}-linux-x64-musl.tar.xz \
39-
&& curl -o- -L https://yarnpkg.com/install.sh | bash \
40-
&& . ~/.bashrc \
41-
&& git clone https://github.com/lightninglabs/lightning-terminal /go/src/github.com/lightninglabs/lightning-terminal \
42-
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
43-
&& git checkout $checkout \
44-
&& make install \
45-
&& make go-install-cli
48+
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
49+
&& make statik-only \
50+
&& make go-install \
51+
&& make go-install-cli
4652

4753
# Start a new, final image to reduce size.
4854
FROM alpine as final
@@ -54,11 +60,11 @@ VOLUME /root/.lnd
5460
EXPOSE 8443 10009 9735
5561

5662
# Copy the binaries and entrypoint from the builder image.
57-
COPY --from=builder /go/bin/litd /bin/
58-
COPY --from=builder /go/bin/lncli /bin/
59-
COPY --from=builder /go/bin/frcli /bin/
60-
COPY --from=builder /go/bin/loop /bin/
61-
COPY --from=builder /go/bin/pool /bin/
63+
COPY --from=golangbuilder /go/bin/litd /bin/
64+
COPY --from=golangbuilder /go/bin/lncli /bin/
65+
COPY --from=golangbuilder /go/bin/frcli /bin/
66+
COPY --from=golangbuilder /go/bin/loop /bin/
67+
COPY --from=golangbuilder /go/bin/pool /bin/
6268

6369
# Add bash.
6470
RUN apk add --no-cache \

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ yarn-install:
9797
# ============
9898
# INSTALLATION
9999
# ============
100-
statik-build: $(STATIK_BIN) app-build
100+
statik-only: $(STATIK_BIN)
101101
@$(call print, "Building statik package.")
102102
statik -src=app/build
103103

104+
statik-build: app-build statik-only
105+
104106
build: statik-build go-build
105107
install: statik-build go-install
106108

@@ -192,6 +194,14 @@ list:
192194
grep -v Makefile | \
193195
sort
194196

197+
protos:
198+
@$(call print, "Compiling protos.")
199+
cd ./app; yarn protos
200+
201+
protos-check: protos
202+
@$(call print, "Verifying compiled protos.")
203+
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
204+
195205
clean:
196206
@$(call print, "Cleaning source.$(NC)")
197207
$(RM) ./lightning-terminal-debug

app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"eject": "react-scripts eject",
1313
"lint": "eslint --ext .ts,.tsx --ignore-path .eslintignore .",
1414
"tsc": "tsc --noEmit",
15-
"postinstall": "yarn protos",
1615
"protos": "node ./scripts/build-protos.js",
1716
"storybook": "start-storybook -p 9009 -s public",
1817
"build-storybook": "build-storybook -s public"

0 commit comments

Comments
 (0)