From 4ba8ee0c91b8db83d6ca3ace9f8ffc4461983807 Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Sun, 22 Dec 2024 07:20:06 -0500 Subject: [PATCH] Use scripts.sh to build within Docker 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. --- Dockerfile | 13 +++++++------ scripts.sh | 26 +++++++++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index ecd68d5..877a734 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] - diff --git a/scripts.sh b/scripts.sh index 771489e..c4420e8 100755 --- a/scripts.sh +++ b/scripts.sh @@ -8,6 +8,7 @@ gen() { } test_go() { + echo "testing" gen # make some files for embed mkdir -p ./frontend/build @@ -15,22 +16,27 @@ test_go() { 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 @@ -46,6 +52,12 @@ case $1 in "dev") dev ;; +"build-frontend") + build_frontend + ;; +"build-backend") + build_backend + ;; "build") build ;;