Skip to content

Commit

Permalink
Fix image build with newer Go version for bootstrap compiler
Browse files Browse the repository at this point in the history
Also simplify the build process in cd.yml
  • Loading branch information
JohnStarich committed Apr 21, 2023
1 parent 534a41d commit f5de9ae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build image
run: make docker
run: make build

test:
runs-on: ubuntu-latest
Expand Down
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f5de9ae

Please sign in to comment.