From 9dd0006ebd2464dc429a343f5f8bc72970a73596 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 14 Dec 2021 23:28:32 +0000 Subject: [PATCH] ci: copy theme assets from Docker container --- docker-compose.yaml | 6 ++++- run | 13 +++++++++++ tools/deployment/deploy/after-update-code.yml | 4 ++-- .../includes/build-theme-assets.yml | 23 ++++--------------- tools/docker/Dockerfile | 20 ++++++++++++++++ 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 09a1445a..7ef9d774 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -50,7 +50,11 @@ services: restart: unless-stopped node: - image: node:14-alpine + build: + context: . + dockerfile: tools/docker/Dockerfile + target: assets + image: ghcr.io/opdavies/oliverdavies-uk-assets:node-14 working_dir: /node entrypoint: sh volumes: diff --git a/run b/run index 6b086133..eeb142cf 100755 --- a/run +++ b/run @@ -7,6 +7,19 @@ if [[ ! -t 1 ]]; then TTY="-T" fi +function task:build-and-push-images { + export DOCKER_BUILDKIT=1 + + docker-compose build assets + docker-compose push assets +} + +function task:copy-theme-assets { + docker container run --entrypoint sh --name oliverdavies-uk-assets oliverdavies-uk-assets + docker cp oliverdavies-uk-assets:/node/build web/themes/custom/opdavies + docker container rm oliverdavies-uk-assets +} + function task:bash { task:exec bash "${@}" } diff --git a/tools/deployment/deploy/after-update-code.yml b/tools/deployment/deploy/after-update-code.yml index 4245e636..a4927723 100644 --- a/tools/deployment/deploy/after-update-code.yml +++ b/tools/deployment/deploy/after-update-code.yml @@ -1,4 +1,6 @@ --- +- include: ../includes/build-theme-assets.yml + - name: Install Composer dependencies composer: command: install @@ -34,5 +36,3 @@ chdir={{ release_web_path }} register: config_import_result changed_when: "'There are no changes to import' not in config_import_result.stderr" - -- include: ../includes/build-theme-assets.yml diff --git a/tools/deployment/includes/build-theme-assets.yml b/tools/deployment/includes/build-theme-assets.yml index 206179ee..fa890789 100644 --- a/tools/deployment/includes/build-theme-assets.yml +++ b/tools/deployment/includes/build-theme-assets.yml @@ -1,19 +1,6 @@ --- -- name: Install theme dependencies - command: > - npm ci - chdir={{ release_theme_path }} - creates={{ release_theme_path }}/node_modules - -- name: Generate front-end assets - command: > - npm run production - chdir={{ release_theme_path }} - creates={{ release_theme_path }}/dist - -- name: Remove files that are no longer needed - file: - path: "{{ release_theme_path }}/{{ item }}" - state: absent - with_items: - - node_modules +- name: Copy theme dependencies from the Docker container. + command: | + docker-compose pull + ./run copy-theme-assets + creates={{ release_theme_path }}/build diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 6c241912..88068053 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -55,3 +55,23 @@ COPY composer.json composer.lock /app/ COPY assets /app/assets COPY tools/patches /app/tools/patches RUN composer install + +### + +FROM node:14-alpine AS assets + +WORKDIR /node + +COPY web/themes/custom/opdavies/package*.json ./ + +RUN npm install + +COPY web/themes/custom/opdavies/postcss.config.js . +COPY web/themes/custom/opdavies/webpack.config.js . +COPY web/themes/custom/opdavies/tailwind.config.js . +COPY web/themes/custom/opdavies/tailwindcss tailwindcss +COPY web/themes/custom/opdavies/assets assets +COPY web/themes/custom/opdavies/templates templates + +RUN npm run prod \ + && rm -fr node_modules