From f5de9aec72b44869a124d38fc95c1ed04965b15c Mon Sep 17 00:00:00 2001 From: John Starich Date: Thu, 20 Apr 2023 23:15:55 -0500 Subject: [PATCH] Fix image build with newer Go version for bootstrap compiler Also simplify the build process in cd.yml --- .github/workflows/cd.yml | 8 ++++---- .github/workflows/ci.yml | 2 +- Dockerfile | 18 +++++++++++------- Makefile | 25 ++++++++++++++----------- server/package.json | 2 +- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a919bdb..cbff689 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -10,16 +10,16 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build - run: make docker + run: make build - name: Publish run: | + out="$(mktemp -d)/out" + mv ./out "$out" git config --global user.email "" git config --global user.name "GitHub Pages Deploy" git checkout --orphan gh-pages git rm -rf . - out=$(mktemp -d) - docker cp $(docker create --rm hackpad):/usr/share/nginx/html "$out" - find "$out/html" -mindepth 1 -maxdepth 1 -exec cp -r {} ./ \; # Glob doesn't always pick up hidden files by default + mv "$out"/* ./ echo hackpad.org > CNAME git add . git commit -am "Deploy to GitHub Pages" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d64c7fe..5f67895 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build image - run: make docker + run: make build test: runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index 0cec77e..b7a0b83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,22 @@ -FROM node:14 as builder - -RUN apt-get update && \ - apt-get install -y golang - +FROM golang:1.20 as go-builder WORKDIR /src # Cache go installation first COPY Makefile /src RUN make go # Build command binaries and static assets COPY . /src -RUN make build +RUN make go-static + +FROM node:14 as node-builder +WORKDIR /src +COPY Makefile /src +COPY ./server /src/server +COPY --from=go-builder /src/server/public/wasm /src/server/public/wasm +RUN make node-static FROM nginx:1 RUN sed -i 's@}@application/wasm wasm;}@' /etc/nginx/mime.types -COPY --from=builder /src/out /usr/share/nginx/html +COPY --from=node-builder /src/server/build/ /usr/share/nginx/html +RUN test -f /usr/share/nginx/html/index.html diff --git a/Makefile b/Makefile index dccf283..7531c16 100644 --- a/Makefile +++ b/Makefile @@ -41,8 +41,8 @@ test-js: go .PHONY: test test: test-native #test-js # TODO restore when this is resolved: https://travis-ci.community/t/goos-js-goarch-wasm-go-run-fails-panic-newosproc-not-implemented/1651 -.PHONY: static -static: server/public/wasm/go.tar.gz commands +.PHONY: go-static +go-static: server/public/wasm/go.tar.gz commands server/public/wasm: mkdir -p server/public/wasm @@ -99,6 +99,11 @@ server/public/wasm/main.wasm: server/public/wasm go server/public/wasm/wasm_exec.js: go cp cache/go/misc/wasm/wasm_exec.js server/public/wasm/wasm_exec.js +.PHONY: node-static +node-static: + npm --prefix=server ci + npm --prefix=server run build + .PHONY: watch watch: @if [[ ! -d server/node_modules ]]; then \ @@ -108,18 +113,16 @@ watch: npm --prefix=server start .PHONY: build -build: static - npm --prefix=server ci - npm --prefix=server run build - mkdir -p out - cp -r server/build/* out/ +build: build-docker + rm -rf ./out + docker cp $$(docker create --rm hackpad):/usr/share/nginx/html ./out -.PHONY: docker -docker: +.PHONY: build-docker +build-docker: docker build -t hackpad . -.PHONY: docker-run -docker-run: docker +.PHONY: run-docker +run-docker: build-docker docker run -it --rm \ --name hackpad \ -p 8080:80 \ diff --git a/server/package.json b/server/package.json index 764d179..9b11166 100644 --- a/server/package.json +++ b/server/package.json @@ -20,7 +20,7 @@ }, "scripts": { "start": "react-scripts start", - "start-go": "cd .. && nodemon --signal SIGINT -e go -d 2 -x 'make static || exit 1'", + "start-go": "cd .. && nodemon --signal SIGINT -e go -d 2 -x 'make go-static || exit 1'", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject"