Skip to content

Commit 09b640c

Browse files
authored
Merge pull request #153 from lightninglabs/prod-docker-file
docker+GitHub: add production Dockerfile and build automatically on tag push
2 parents b84ae0b + 1b46786 commit 09b640c

File tree

5 files changed

+170
-10
lines changed

5 files changed

+170
-10
lines changed

.github/workflows/docker.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Docker image build
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
env:
14+
DOCKER_REPO: lightninglabs
15+
DOCKER_IMAGE: lightning-terminal
16+
17+
jobs:
18+
main:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v1
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v1
26+
27+
- name: Login to DockerHub
28+
uses: docker/login-action@v1
29+
with:
30+
username: ${{ secrets.DOCKER_USERNAME }}
31+
password: ${{ secrets.DOCKER_API_KEY }}
32+
33+
- name: Set env
34+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
35+
36+
- name: Build and push
37+
id: docker_build
38+
uses: docker/build-push-action@v2
39+
with:
40+
push: true
41+
tags: "${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}"
42+
build-args: checkout=${{ env.RELEASE_VERSION }}
43+
44+
- name: Image digest
45+
run: echo ${{ steps.docker_build.outputs.digest }}

Dockerfile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
FROM golang:1.15.5-alpine as builder
22

3-
# Copy in the local repository to build from.
4-
COPY . /go/src/github.com/lightninglabs/lightning-terminal
5-
63
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
74
# queries required to connect to linked containers succeed.
85
ENV GODEBUG netdns=cgo
96

7+
# Pass a tag, branch or a commit using build-arg. This allows a docker image to
8+
# be built from a specified Git state. The default image will use the Git tip of
9+
# master by default.
10+
ARG checkout="master"
11+
1012
# Explicitly turn on the use of modules (until this becomes the default).
1113
ENV GO111MODULE on
1214

1315
ENV NODE_VERSION=v12.17.0
1416

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"
21+
1522
# Install dependencies and install/build lightning-terminal.
1623
RUN apk add --no-cache --update alpine-sdk \
1724
git \
@@ -21,18 +28,21 @@ RUN apk add --no-cache --update alpine-sdk \
2128
binutils \
2229
tar \
2330
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 \
2435
&& touch ~/.bashrc \
2536
&& curl -sfSLO https://unofficial-builds.nodejs.org/download/release/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64-musl.tar.xz \
2637
&& tar -xf node-${NODE_VERSION}-linux-x64-musl.tar.xz -C /usr --strip 1 \
2738
&& rm node-${NODE_VERSION}-linux-x64-musl.tar.xz \
2839
&& curl -o- -L https://yarnpkg.com/install.sh | bash \
2940
&& . ~/.bashrc \
30-
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
31-
&& make install \
32-
&& go install -v -trimpath github.com/lightningnetwork/lnd/cmd/lncli \
33-
&& go install -v -trimpath github.com/lightninglabs/faraday/cmd/frcli \
34-
&& go install -v -trimpath github.com/lightninglabs/loop/cmd/loop \
35-
&& go install -v -trimpath github.com/lightninglabs/pool/cmd/pool
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
3646

3747
# Start a new, final image to reduce size.
3848
FROM alpine as final

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ go-install:
112112
@$(call print, "Installing lightning-terminal.")
113113
$(GOINSTALL) -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" $(PKG)/cmd/litd
114114

115+
go-install-cli:
116+
@$(call print, "Installing all CLI binaries.")
117+
$(GOINSTALL) -trimpath -tags="$(LND_RELEASE_TAGS)" -ldflags "$(LDFLAGS)" github.com/lightningnetwork/lnd/cmd/lncli
118+
$(GOINSTALL) -trimpath -ldflags "$(LDFLAGS)" github.com/lightninglabs/loop/cmd/loop
119+
$(GOINSTALL) -trimpath github.com/lightninglabs/faraday/cmd/frcli
120+
$(GOINSTALL) -trimpath github.com/lightninglabs/pool/cmd/pool
121+
115122
app-build: yarn-install
116123
@$(call print, "Building production app.")
117124
cd app; yarn build

dev.Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM golang:1.15.5-alpine as builder
2+
3+
# Copy in the local repository to build from.
4+
COPY . /go/src/github.com/lightninglabs/lightning-terminal
5+
6+
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
7+
# queries required to connect to linked containers succeed.
8+
ENV GODEBUG netdns=cgo
9+
10+
# Explicitly turn on the use of modules (until this becomes the default).
11+
ENV GO111MODULE on
12+
13+
ENV NODE_VERSION=v12.17.0
14+
15+
# Install dependencies and install/build lightning-terminal.
16+
RUN apk add --no-cache --update alpine-sdk \
17+
git \
18+
make \
19+
curl \
20+
bash \
21+
binutils \
22+
tar \
23+
protobuf-dev \
24+
&& touch ~/.bashrc \
25+
&& curl -sfSLO https://unofficial-builds.nodejs.org/download/release/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64-musl.tar.xz \
26+
&& tar -xf node-${NODE_VERSION}-linux-x64-musl.tar.xz -C /usr --strip 1 \
27+
&& rm node-${NODE_VERSION}-linux-x64-musl.tar.xz \
28+
&& curl -o- -L https://yarnpkg.com/install.sh | bash \
29+
&& . ~/.bashrc \
30+
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
31+
&& make install \
32+
&& make go-install-cli
33+
34+
# Start a new, final image to reduce size.
35+
FROM alpine as final
36+
37+
# Define a root volume for data persistence.
38+
VOLUME /root/.lnd
39+
40+
# Expose lightning-terminal and lnd ports (server, rpc).
41+
EXPOSE 8443 10009 9735
42+
43+
# Copy the binaries and entrypoint from the builder image.
44+
COPY --from=builder /go/bin/litd /bin/
45+
COPY --from=builder /go/bin/lncli /bin/
46+
COPY --from=builder /go/bin/frcli /bin/
47+
COPY --from=builder /go/bin/loop /bin/
48+
COPY --from=builder /go/bin/pool /bin/
49+
50+
# Add bash.
51+
RUN apk add --no-cache \
52+
bash \
53+
jq \
54+
ca-certificates
55+
56+
# Specify the start command and entrypoint as the lightning-terminal daemon.
57+
ENTRYPOINT ["litd"]

doc/compile.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ installed on your machine.
66
| Dependency | Description |
77
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
88
| [golang](https://golang.org/doc/install) | LiT's backend web server is written in Go. The minimum version supported is Go v1.13. |
9-
| [protoc](https://grpc.io/docs/protoc-installation/) | Required to compile LND & Loop gRPC proto files at build time. |
9+
| [protoc 3.4.0](https://github.com/lightningnetwork/lnd/tree/master/lnrpc#generate-protobuf-definitions) | Required to compile LND & Loop gRPC proto files at build time. Must be installed according to step 1 of the linked guide. |
1010
| [nodejs](https://nodejs.org/en/download/) | LiT's frontend is written in TypeScript and built on top of the React JS web framework. To bundle the assets into Javascript & CSS compatible with web browsers, NodeJS is required. |
1111
| [yarn](https://classic.yarnpkg.com/en/docs/install) | A popular package manager for NodeJS application dependencies. |
1212

@@ -26,3 +26,44 @@ need to download those binaries from the
2626
[loop](https://github.com/lightninglabs/loop/releases),
2727
[pool](https://github.com/lightninglabs/pool/releases), and
2828
[faraday](https://github.com/lightninglabs/faraday/releases) repos manually.
29+
30+
## Building a docker image
31+
32+
There are two flavors of Dockerfiles available:
33+
- `Dockerfile`: Used for production builds. Checks out the source code from
34+
GitHub during build. The build argument `--build-arg checkout=v0.x.x-alpha`
35+
can be used to specify what git tag or commit to check out before building.
36+
- `dev.Dockerfile` Used for development or testing builds. Uses the local code
37+
when building and allows local changes to be tested more easily.
38+
39+
### Building a development docker image
40+
41+
Follow the instructions of the [previous chapter](#compile-from-source-code) to
42+
install all necessary dependencies.
43+
44+
Then, instead of `make install` run the following commands:
45+
46+
```shell script
47+
$ docker build -f dev.Dockerfile -t my-lit-dev-image .
48+
```
49+
50+
If successful, you can then run the docker image with:
51+
52+
```shell script
53+
$ docker run -p 8443:8443 --rm --name litd my-lit-dev-image \
54+
--httpslisten=0.0.0.0:8443 \
55+
... (your configuration flags here)
56+
```
57+
58+
See the [execution section in the main README](../README.md#execution) to find
59+
out what configuration flags to use.
60+
61+
### Building a production docker image
62+
63+
To create a production build, you need to specify the git tag to create the
64+
image from. All local files will be ignored, everything is cloned and built from
65+
GitHub so you don't need to install any dependencies:
66+
67+
```shell script
68+
$ docker build -t lightninglabs/lightning-terminal --build-arg checkout=v0.3.2-alpha .
69+
```

0 commit comments

Comments
 (0)