From 9b7fe558701376868727011a0f47a16fdbe93c32 Mon Sep 17 00:00:00 2001 From: x1unix Date: Fri, 15 Apr 2022 16:35:04 +0200 Subject: [PATCH 1/2] make: take advantage of '--cwd' flag for yarn --- Makefile | 2 +- build.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index da39955b..e390c9d4 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ run: .PHONY:ui ui: - @cd $(UI) && REACT_APP_LANG_SERVER='//$(LISTEN_ADDR)' REACT_APP_VERSION=testing yarn start + @REACT_APP_LANG_SERVER='//$(LISTEN_ADDR)' REACT_APP_VERSION=testing yarn --cwd="$(UI)" start .PHONY: cover cover: diff --git a/build.mk b/build.mk index 75248426..8984e3b3 100644 --- a/build.mk +++ b/build.mk @@ -32,7 +32,7 @@ collect-meta: .PHONY:preinstall preinstall: @echo ":: Checking and installing dependencies..." && \ - cd $(UI) && $(YARN) install --silent + $(YARN) --cwd="$(UI)" install --silent .PHONY:build-server build-server: @@ -42,7 +42,7 @@ build-server: .PHONY:build-ui build-ui: @echo ":: Building UI..." && \ - cd $(UI) && $(YARN) build + $(YARN) --cwd="$(UI)" build .PHONY:build-webworker build-webworker: From b85721960709412235e7e115e4a198292f1c9985 Mon Sep 17 00:00:00 2001 From: x1unix Date: Fri, 15 Apr 2022 16:59:33 +0200 Subject: [PATCH 2/2] ci: build frontend outside of main dockerfile --- .github/workflows/release.yml | 9 ++++++- build/release.dockerfile | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 build/release.dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7406c4d0..a4bb5d9b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,11 +54,18 @@ jobs: - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 + - name: Build frontend + uses: addnab/docker-run-action@v3 + with: + image: node:lts-gallium + 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 + run: | + yarn --cwd='/work' install --silent && yarn --cwd='/work' build - name: Build and push image uses: docker/build-push-action@v2 with: context: . - file: ./build/Dockerfile + file: ./build/release.dockerfile platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/build/release.dockerfile b/build/release.dockerfile new file mode 100644 index 00000000..9517f5b7 --- /dev/null +++ b/build/release.dockerfile @@ -0,0 +1,44 @@ +# This dockerfile is intended to run only by GitHub Actions +# for multi-arch builds. +# +# This Dockerfile builds only Go code, because building +# frontend twice for different platform takes too long +# inside VM and makes no sence. +# +# Use Dockerfile for simple single-arch build process + +FROM golang:1.18-alpine as build +WORKDIR /tmp/playground +COPY cmd ./cmd +COPY pkg ./pkg +COPY go.mod . +COPY go.sum . +ARG APP_VERSION=1.0.0 +RUN echo "Building server with version $APP_VERSION" && \ + go build -o server -ldflags="-X 'main.Version=$APP_VERSION'" ./cmd/playground && \ + GOOS=js GOARCH=wasm go build -o ./worker.wasm ./cmd/webworker && \ + cp $(go env GOROOT)/misc/wasm/wasm_exec.js . + +FROM golang:1.18-alpine as production +WORKDIR /opt/playground +ENV GOROOT /usr/local/go +ENV APP_CLEAN_INTERVAL=10m +ENV APP_DEBUG=false +ENV APP_PLAYGROUND_URL='https://play.golang.org' +ENV APP_GOTIP_URL='https://gotipplay.golang.org' +ENV APP_GTAG_ID='' +COPY data ./data +COPY /tmp/web/build ./public +COPY --from=build /tmp/playground/server . +COPY --from=build /tmp/playground/worker.wasm ./public +COPY --from=build /tmp/playground/wasm_exec.js ./public +EXPOSE 8000 +ENTRYPOINT /opt/playground/server \ + -f='/opt/playground/data/packages.json' \ + -clean-interval="${APP_CLEAN_INTERVAL}" \ + -debug="${APP_DEBUG}" \ + -playground-url="${APP_PLAYGROUND_URL}" \ + -gotip-url="${APP_GOTIP_URL}" \ + -gtag-id="${APP_GTAG_ID}" \ + -permit-env-vars="${APP_PERMIT_ENV_VARS}" \ + -addr=:8000 \ No newline at end of file