Update workflow using Dockerfile. (#1003)

This commit is contained in:
Googol Lee
2024-08-03 23:17:54 +02:00
committed by GitHub
parent 4d9ce30583
commit ebcbe6c057
11 changed files with 155 additions and 151 deletions

View File

@@ -2,7 +2,7 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:18 AS ui
# See for details: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
ARG REACT_APP_API_ENDPOINT
ENV REACT_APP_API_ENDPOINT=${REACT_APP_API_ENDPOINT}
@@ -23,22 +23,21 @@ ARG COMMIT_SHA
ENV COMMIT_SHA=${COMMIT_SHA:-}
ENV REACT_APP_BUILD_COMMIT_SHA=${COMMIT_SHA:-}
# Download dependencies
COPY ui /app/ui
WORKDIR /app/ui
RUN npm ci --omit=dev --ignore-scripts \
# Build frontend
&& npm run build -- --base=$UI_PUBLIC_URL
COPY ui/package.json ui/package-lock.json /app/ui
RUN npm ci
COPY ui/ /app/ui
RUN npm run build -- --base=$UI_PUBLIC_URL
### Build API ###
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.22-bookworm AS api
ARG TARGETPLATFORM
# See for details: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
COPY scripts /app/scripts
COPY api /app/api
WORKDIR /app/api
ENV GOPATH="/go"
@@ -46,9 +45,13 @@ ENV PATH="${GOPATH}/bin:${PATH}"
ENV CGO_ENABLED=1
# Download dependencies
COPY scripts/*.sh /app/scripts/
RUN chmod +x /app/scripts/*.sh \
&& source /app/scripts/set_compiler_env.sh \
&& /app/scripts/install_build_dependencies.sh \
&& /app/scripts/install_runtime_dependencies.sh
COPY api/go.mod api/go.sum /app/api/
RUN source /app/scripts/set_compiler_env.sh \
&& go env \
&& go mod download \
# Patch go-face
@@ -56,38 +59,29 @@ RUN chmod +x /app/scripts/*.sh \
# Build dependencies that use CGO
&& go install \
github.com/mattn/go-sqlite3 \
github.com/Kagami/go-face \
# Build api source
&& go build -v -o photoview .
github.com/Kagami/go-face
### Build dev image for UI ###
FROM ui AS dev-ui
### Build dev image for API ###
FROM api AS dev-api
COPY api /app/api
RUN source /app/scripts/set_compiler_env.sh \
&& /app/scripts/install_runtime_dependencies.sh \
## Install dev tools
&& apt update \
&& apt install -y reflex sqlite3
&& go build -v -o photoview .
### Build release image ###
FROM --platform=${BUILDPLATFORM:-linux/amd64} debian:bookworm-slim AS release
ARG TARGETPLATFORM
# See for details: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
COPY scripts/install_runtime_dependencies.sh /app/scripts/
# Create a user to run Photoview server
RUN groupadd -g 999 photoview \
RUN chmod +x /app/scripts/install_runtime_dependencies.sh \
# Create a user to run Photoview server
&& groupadd -g 999 photoview \
&& useradd -r -u 999 -g photoview -m photoview \
# Required dependencies
&& chmod +x /app/scripts/*.sh \
&& /app/scripts/install_runtime_dependencies.sh
WORKDIR /home/photoview
COPY api/data /app/data
COPY --from=ui /app/ui/dist /app/ui
COPY --from=api /app/api/photoview /app/photoview