From c4da10b15ffb32e830a8976a6e64d7cb9b099dbb Mon Sep 17 00:00:00 2001 From: sjaanus Date: Tue, 30 Aug 2022 12:39:28 +0000 Subject: [PATCH] Docker cross-compilation with buildx (#2003) * Build docker test * Change platform to build on amd64 * Put back buildplatform * Run frontend as separate docker task * Increase timeout * Update docs --- .dockerignore | 1 + CONTRIBUTING.md | 4 ++-- Dockerfile | 15 ++++++++++++--- package.json | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 8c611ae669..84f97f0519 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,4 @@ !README.md !frontend frontend/node_modules +frontend/build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 030de11637..01a72bcace 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -112,9 +112,9 @@ You'll need: - username: `admin` - password: `unleash4all` -### How to run Unleash with Docker +### How to run Unleash with Docker and Buildx -1. Build a local docker image by running `docker build . -t unleash:local` +1. Build a local docker image by running `docker buildx build . -t unleash:local` 2. Create a network by running `docker network create unleash` 3. Start a Postgres database. Make sure to use the network you created in step 2. diff --git a/Dockerfile b/Dockerfile index 984048501f..7560d48f68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,14 @@ ARG NODE_VERSION=16-alpine -FROM node:$NODE_VERSION as builder -RUN echo "Debug - node version: $NODE_VERSION " +FROM --platform=$BUILDPLATFORM node:$NODE_VERSION as frontend_builder + +WORKDIR /frontend + +COPY ./frontend /frontend + +RUN yarn install --frozen-lockfile + +FROM node:$NODE_VERSION as builder WORKDIR /unleash @@ -9,7 +16,9 @@ COPY . /unleash RUN yarn config set network-timeout 300000 -RUN yarn install --frozen-lockfile && yarn run local:package +RUN yarn install --frozen-lockfile --ignore-scripts && yarn run build && yarn run local:package + +COPY --from=frontend_builder /frontend/build /unleash/build/frontend/build WORKDIR /unleash/docker diff --git a/package.json b/package.json index a8f0cc2251..da3da0020f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "copy-templates": "copyfiles -u 1 src/mailtemplates/**/*.mustache dist/", "db-migrate": "db-migrate --migrations-dir ./src/migrations", "lint": "eslint ./src", - "local:package": "del-cli --force build && mkdir build && cp -r dist docs CHANGELOG.md LICENSE README.md package.json build && mkdir -p build/frontend && cp -r frontend/build build/frontend", + "local:package": "del-cli --force build && mkdir build && cp -r dist docs CHANGELOG.md LICENSE README.md package.json build", "prebuild:watch": "yarn run clean", "build:watch": "tsc -w", "prebuild": "yarn run clean",