Skip to content

Commit 05d32f4

Browse files
authored
Speedup build process (#160)
* make: take advantage of '--cwd' flag for yarn * ci: build frontend outside of main dockerfile
1 parent 850fcc1 commit 05d32f4

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ jobs:
5454
- name: Set up Docker Buildx
5555
id: buildx
5656
uses: docker/setup-buildx-action@v1
57+
- name: Build frontend
58+
uses: addnab/docker-run-action@v3
59+
with:
60+
image: node:lts-gallium
61+
options: -v ${{ github.workspace }}/web:/work -e REACT_APP_VERSION=${{ env.RELEASE_VERSION }} -e REACT_APP_GITHUB_URL='https://github.com/x1unix/go-playground' -e NODE_ENV=production
62+
run: |
63+
yarn --cwd='/work' install --silent && yarn --cwd='/work' build
5764
- name: Build and push image
5865
uses: docker/build-push-action@v2
5966
with:
6067
context: .
61-
file: ./build/Dockerfile
68+
file: ./build/release.dockerfile
6269
platforms: linux/amd64,linux/arm64
6370
tags: ${{ steps.meta.outputs.tags }}
6471
labels: ${{ steps.meta.outputs.labels }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ run:
2828

2929
.PHONY:ui
3030
ui:
31-
@cd $(UI) && REACT_APP_LANG_SERVER='//$(LISTEN_ADDR)' REACT_APP_VERSION=testing yarn start
31+
@REACT_APP_LANG_SERVER='//$(LISTEN_ADDR)' REACT_APP_VERSION=testing yarn --cwd="$(UI)" start
3232

3333
.PHONY: cover
3434
cover:

build.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ collect-meta:
3232
.PHONY:preinstall
3333
preinstall:
3434
@echo ":: Checking and installing dependencies..." && \
35-
cd $(UI) && $(YARN) install --silent
35+
$(YARN) --cwd="$(UI)" install --silent
3636

3737
.PHONY:build-server
3838
build-server:
@@ -42,7 +42,7 @@ build-server:
4242
.PHONY:build-ui
4343
build-ui:
4444
@echo ":: Building UI..." && \
45-
cd $(UI) && $(YARN) build
45+
$(YARN) --cwd="$(UI)" build
4646

4747
.PHONY:build-webworker
4848
build-webworker:

build/release.dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This dockerfile is intended to run only by GitHub Actions
2+
# for multi-arch builds.
3+
#
4+
# This Dockerfile builds only Go code, because building
5+
# frontend twice for different platform takes too long
6+
# inside VM and makes no sence.
7+
#
8+
# Use Dockerfile for simple single-arch build process
9+
10+
FROM golang:1.18-alpine as build
11+
WORKDIR /tmp/playground
12+
COPY cmd ./cmd
13+
COPY pkg ./pkg
14+
COPY go.mod .
15+
COPY go.sum .
16+
ARG APP_VERSION=1.0.0
17+
RUN echo "Building server with version $APP_VERSION" && \
18+
go build -o server -ldflags="-X 'main.Version=$APP_VERSION'" ./cmd/playground && \
19+
GOOS=js GOARCH=wasm go build -o ./worker.wasm ./cmd/webworker && \
20+
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
21+
22+
FROM golang:1.18-alpine as production
23+
WORKDIR /opt/playground
24+
ENV GOROOT /usr/local/go
25+
ENV APP_CLEAN_INTERVAL=10m
26+
ENV APP_DEBUG=false
27+
ENV APP_PLAYGROUND_URL='https://play.golang.org'
28+
ENV APP_GOTIP_URL='https://gotipplay.golang.org'
29+
ENV APP_GTAG_ID=''
30+
COPY data ./data
31+
COPY /tmp/web/build ./public
32+
COPY --from=build /tmp/playground/server .
33+
COPY --from=build /tmp/playground/worker.wasm ./public
34+
COPY --from=build /tmp/playground/wasm_exec.js ./public
35+
EXPOSE 8000
36+
ENTRYPOINT /opt/playground/server \
37+
-f='/opt/playground/data/packages.json' \
38+
-clean-interval="${APP_CLEAN_INTERVAL}" \
39+
-debug="${APP_DEBUG}" \
40+
-playground-url="${APP_PLAYGROUND_URL}" \
41+
-gotip-url="${APP_GOTIP_URL}" \
42+
-gtag-id="${APP_GTAG_ID}" \
43+
-permit-env-vars="${APP_PERMIT_ENV_VARS}" \
44+
-addr=:8000

0 commit comments

Comments
 (0)