Skip to content

Commit

Permalink
Use scripts.sh to build within Docker
Browse files Browse the repository at this point in the history
Docker currently duplicates the build logic from scripts.sh. It's not a big deal now because it's only a couple of standard lines, but if we want to customize the build in the future, it will be useful to have a single, authoritative build script that all build paths use.
  • Loading branch information
mtlynch committed Dec 22, 2024
1 parent d1b41a6 commit 4ba8ee0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# build frontend
FROM node:22 as fe
WORKDIR /src
COPY .git frontend ./
RUN npm i && npm run build
COPY .git .git/
COPY frontend ./frontend
COPY scripts.sh .
RUN ./scripts.sh build-frontend

# build backend
FROM golang:1.23 as be
WORKDIR /src
COPY . ./
COPY --from=fe /src/build ./frontend/build/
RUN go build -o fusion ./cmd/server/*
COPY --from=fe /src/frontend/build ./frontend/build/
RUN ./scripts.sh build-backend

# deploy
FROM debian:12
LABEL org.opencontainers.image.source="https://github.com/0x2E/fusion"
RUN apt-get update && apt-get install -y sqlite3 ca-certificates
WORKDIR /fusion
COPY --from=be /src/fusion ./
COPY --from=be /src/build/fusion ./
EXPOSE 8080
RUN mkdir /data
ENV DB="/data/fusion.db"
CMD [ "./fusion" ]

26 changes: 19 additions & 7 deletions scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,35 @@ gen() {
}

test_go() {
echo "testing"
gen
# make some files for embed
mkdir -p ./frontend/build
touch ./frontend/build/index.html
go test ./...
}

build() {
echo "testing"
gen
test_go

root=$(pwd)
mkdir -p ./build
build_frontend() {
echo "building frontend"
mkdir -p ./build
root=$(pwd)
cd ./frontend
npm i
npm run build
cd $root
}

build_backend() {
echo "building backend"
go build -o ./build/fusion ./cmd/server/*
}

build() {
test_go
build_frontend
build_backend
}

dev() {
gen
go run ./cmd/server
Expand All @@ -46,6 +52,12 @@ case $1 in
"dev")
dev
;;
"build-frontend")
build_frontend
;;
"build-backend")
build_backend
;;
"build")
build
;;
Expand Down

0 comments on commit 4ba8ee0

Please sign in to comment.