From e0ac8ddd240f28056e753498eb0f41ed95323771 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Thu, 29 Apr 2021 10:45:42 +0200 Subject: [PATCH] [#44] [#44] Release container now builds & packages frontend as well --- .dockerignore | 32 +++++++++++++++++++++++++++----- docker/Dockerfile.rel | 17 ++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index a96bd42..b143673 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,20 +1,42 @@ * -# Source code +# =====BACKEND===== +## Source code !src/ -# Cargo files +## Cargo files !Cargo.toml !Cargo.lock -# Entrypoint for devop container +## Entrypoint for devop container !docker/entrypoint_dev.sh !docker/entrypoint.sh -# Config file +## Config file !Rocket.toml -# Database migrations +## Database migrations !migrations/ +## Crontab for release container !docker/crontab + + +# =====FRONTEND===== +## Source code +!web/src/ + +## Public assets +!web/public/ +!web/index.html + +## Production env file +!web/.env.production + +## Package manager stuff +!web/package.json +!web/yarn.lock + +## Project configs +!web/tsconfig.json +!web/vite.config.ts diff --git a/docker/Dockerfile.rel b/docker/Dockerfile.rel index 4bffeae..a01d343 100644 --- a/docker/Dockerfile.rel +++ b/docker/Dockerfile.rel @@ -1,5 +1,5 @@ # vim: filetype=dockerfile -FROM chewingbever/fej-builder:latest AS builder +FROM chewingbever/fej-builder:latest AS backend-builder COPY --chown=builder:builder Cargo.toml Cargo.lock ./ COPY --chown=builder:builder src/ ./src/ @@ -22,6 +22,16 @@ RUN cargo install \ --target x86_64-unknown-linux-musl +FROM node:15-alpine3.13 AS frontend-builder + +COPY ./web /app +WORKDIR /app + +# Build the frontend +RUN yarn install && \ + yarn run build + + # Now, we create the actual image FROM alpine:3.13.5 COPY ./docker/crontab /var/spool/cron/crontabs/fej @@ -41,8 +51,9 @@ RUN apk update && \ # Switch to non-root user USER fej:fej -# Copy binary over to final image -COPY --from=builder --chown=fej:fej /app/output/bin /app/bin +# Copy binary & frontend over to final image +COPY --from=backend-builder --chown=fej:fej /app/output/bin /app/bin +COPY --from=frontend-builder --chown=fej:fej /app/dist /app/dist # Embed config file inside container # The workdir is changed so that the config file is read properly