Skip to content

Commit ee0d41b

Browse files
authored
Build Docker image (#8)
* Build Docker image * Run CI build * Remove line for debugging * Remove debugging for Docker image * Remove static folder from Docker image
1 parent dc3a420 commit ee0d41b

File tree

4 files changed

+158
-5
lines changed

4 files changed

+158
-5
lines changed

.circleci/config.yml

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,84 @@ jobs:
7474
root: ./
7575
paths:
7676
- ./bin/screenjournal
77+
build_docker_images:
78+
docker:
79+
- image: cimg/base:stable
80+
environment:
81+
BUILD_TARGETS: "linux/arm/v7,linux/arm64,linux/amd64"
82+
steps:
83+
- checkout
84+
- setup_remote_docker:
85+
version: 20.10.11
86+
- run:
87+
name: Log in to Docker Hub
88+
command: |
89+
echo "${DOCKERHUB_ACCESS_TOKEN}" | \
90+
docker login --username "${DOCKERHUB_USERNAME}" --password-stdin
91+
- run:
92+
name: Enable multiarch builds with QEMU
93+
command: |
94+
docker run \
95+
--rm \
96+
--privileged \
97+
multiarch/qemu-user-static \
98+
--reset \
99+
-p yes
100+
- run:
101+
name: Create multiarch build context
102+
command: docker context create builder
103+
- run:
104+
name: Create multiplatform builder
105+
command: |
106+
docker buildx create builder \
107+
--name builder \
108+
--driver docker-container \
109+
--use
110+
- run:
111+
name: Ensure builder has booted
112+
command: docker buildx inspect --bootstrap
113+
- run:
114+
name: Build docker images
115+
command: |
116+
docker buildx build \
117+
--push \
118+
--platform "$BUILD_TARGETS" \
119+
--tag "mtlynch/screenjournal:${CIRCLE_TAG}" \
120+
--tag mtlynch/screenjournal:latest \
121+
.
77122
workflows:
78123
version: 2
79124
test_deploy:
80125
jobs:
81-
- check_whitespace
82-
- check_bash
83-
- check_frontend
84-
- test_go
85-
- build_backend
126+
- check_whitespace:
127+
filters:
128+
tags:
129+
only: /.*/
130+
- check_bash:
131+
filters:
132+
tags:
133+
only: /.*/
134+
- check_frontend:
135+
filters:
136+
tags:
137+
only: /.*/
138+
- test_go:
139+
filters:
140+
tags:
141+
only: /.*/
142+
- build_backend:
143+
filters:
144+
tags:
145+
only: /.*/
146+
- build_docker_images:
147+
requires:
148+
- check_whitespace
149+
- check_bash
150+
- check_frontend
151+
- test_go
152+
- build_backend
153+
filters:
154+
tags:
155+
only: /[0-9]+(\.[0-9]+){2}/
156+
branches:
157+
ignore: /.*/

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM golang:1.19.1 AS builder
2+
3+
ARG TARGETPLATFORM
4+
5+
COPY ./cmd /app/cmd
6+
COPY ./handlers /app/handlers
7+
COPY ./go.* /app/
8+
9+
WORKDIR /app
10+
11+
RUN set -x && \
12+
if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
13+
GOARCH="arm"; \
14+
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
15+
GOARCH="arm64"; \
16+
else \
17+
GOARCH="amd64"; \
18+
fi && \
19+
set -u && \
20+
GOOS=linux \
21+
go build \
22+
-tags netgo \
23+
-ldflags '-w -extldflags "-static"' \
24+
-o /app/screenjournal \
25+
cmd/screenjournal/main.go
26+
27+
FROM alpine:3.15
28+
29+
RUN apk add --no-cache bash
30+
31+
COPY --from=builder /app/screenjournal /app/screenjournal
32+
COPY ./docker-entrypoint /app/docker-entrypoint
33+
COPY ./static /app/static
34+
COPY ./LICENSE /app/LICENSE
35+
36+
WORKDIR /app
37+
38+
ENTRYPOINT ["/app/docker-entrypoint"]

dev-scripts/serve-docker

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Exit build script on first failure.
4+
set -e
5+
6+
# Echo commands to stdout.
7+
set -x
8+
9+
# Exit on unset variable.
10+
set -u
11+
12+
# Change directory to repository root.
13+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
14+
readonly SCRIPT_DIR
15+
cd "${SCRIPT_DIR}/.."
16+
17+
DOCKER_BUILDKIT=1 \
18+
docker build -t screenjournal .
19+
20+
docker rm -f screenjournal || true
21+
22+
docker run \
23+
--env "PORT=4002" \
24+
--publish "0.0.0.0:4002:4002" \
25+
--name screenjournal \
26+
screenjournal

docker-entrypoint

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Exit build script on first failure.
4+
set -e
5+
6+
# Exit on unset variable.
7+
set -u
8+
9+
SJ_ARGS="$*"
10+
readonly SJ_ARGS
11+
12+
# Echo commands to stdout.
13+
set -x
14+
15+
SJ_LAUNCH_CMD="/app/screenjournal ${SJ_ARGS}"
16+
17+
eval "${SJ_LAUNCH_CMD}"

0 commit comments

Comments
 (0)