[c] Dockerfile refactoring
All checks were successful
Build and push docker image / deploy (push) Successful in 44s

This commit is contained in:
Sangelo 2024-04-12 09:35:09 +02:00
parent bcca482355
commit 24e0e9f29b

View file

@ -2,25 +2,25 @@
FROM node:20-alpine AS builder FROM node:20-alpine AS builder
# Set the working directory in the container # Set the working directory in the container
WORKDIR /app WORKDIR /git
# Copy the repository contents into the container # Copy the repository contents into the container
COPY . . COPY . .
# Install dependencies and build the site. Output directory will be /app/build # Install dependencies and build the site. Output directory will be /git/build
RUN yarn install && yarn run build RUN yarn install && yarn run build
# Final stage # Final stage
FROM caddy:2-alpine FROM caddy:2-alpine
# Set the working directory in the container # Set the working directory in the container
WORKDIR /web WORKDIR /app
# Copy the build directory from the builder stage to /web # Copy the build directory from the builder stage to /app
COPY --from=builder /app/build /web COPY --from=builder /git/build /app
# Caddyfile configuration to serve files from /web # Caddyfile configuration to serve files from /app
RUN echo -e ":80 {\n root * /web\n file_server\n}" > /etc/caddy/Caddyfile RUN echo -e ":80 {\n root * /app\n try_files {path}.html {path}\n file_server\n}" > /etc/caddy/Caddyfile
# Expose port 80 # Expose port 80
EXPOSE 80 EXPOSE 80
@ -32,10 +32,10 @@ CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile
LABEL org.opencontainers.image.title="Sangelo's Space" LABEL org.opencontainers.image.title="Sangelo's Space"
LABEL org.opencontainers.image.description="Sangelo's Space website, packaged as a docker container, with the Caddy webserver." LABEL org.opencontainers.image.description="Sangelo's Space website, packaged as a docker container, with the Caddy webserver."
LABEL org.opencontainers.image.url="https://sangelo.space" LABEL org.opencontainers.image.url="https://sangelo.space"
LABEL org.opencontainers.image.documentation="https://gitpot.org/sangelo/website" LABEL org.opencontainers.image.documentation="https://git.org/sangelo/appsite"
LABEL org.opencontainers.image.vendor="Sangelo" LABEL org.opencontainers.image.vendor="Sangelo"
LABEL org.opencontainers.image.licenses="GPL-v3" LABEL org.opencontainers.image.licenses="GPL-v3"
LABEL org.opencontainers.image.source="https://gitpot.org/sangelo/website" LABEL org.opencontainers.image.source="https://git.org/sangelo/appsite"
# Remove intermediate images after build # Remove intermediate images after build
ONBUILD RUN rm -rf /app ONBUILD RUN rm -rf /git