Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
build(docker): use Tailwind CLI for generating CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
opdavies committed Dec 28, 2021
1 parent 84963c8 commit 86e9a49
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 4,246 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
IFTTT_WEBHOOK_URL=

INTEGROMAT_WEBHOOK_URL=

# Which environment is running? This should be "development" or "production".
# NODE_ENV=development
NODE_ENV=production
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ jobs:
path: node_modules
key: dependencies-npm-${{ hashFiles('package-lock.json') }}

- name: Build the production theme assets
run: |
cd ${{ matrix.theme-path }}
npm clean-install
npm run production
phpunit:
runs-on: ubuntu-latest
name: "Run ${{ matrix.test-types }} tests"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
!/bin/
!/config/**
!/Dockerfile
!/docker-compose.override.yaml.example
!/docker-compose.yaml
!/phpcs.xml.dist
!/phpstan*.neon
Expand Down
30 changes: 22 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
FROM node:14-alpine AS assets
FROM node:14-buster-slim AS assets

ARG NODE_ENV=production
ENV NODE_ENV="${NODE_ENV:-production}" \
PATH="${PATH}:/node_modules/.bin"

WORKDIR /app

RUN mkdir /node_modules \
chown node:node -R /node_modules /app
&& chown node:node -R /node_modules /app

USER node

COPY --chown=node:node run .

WORKDIR /app/web/themes/custom/opdavies
COPY web/themes/custom/opdavies/.yarnrc .
COPY web/themes/custom/opdavies/package.json .
COPY web/themes/custom/opdavies/yarn.lock .
RUN yarn install && yarn cache clear
COPY web/themes/custom/opdavies ./
RUN npm run production

COPY --chown=node:node web/themes/custom/opdavies/.yarnrc .
COPY --chown=node:node web/themes/custom/opdavies/package.json .
COPY --chown=node:node web/themes/custom/opdavies/yarn.lock .

RUN yarn install && yarn cache clean

COPY --chown=node:node ../../../../config ../../../../config

CMD ["bash"]

###

Expand Down
17 changes: 17 additions & 0 deletions docker-compose.override.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
x-assets: &default-assets
build:
context: .
target: assets
args:
- "NODE_ENV=${NODE_ENV:-production}"
env_file:
- .env
tty: true
volumes:
- '.:/app'

services:
css:
<<: *default-assets
command: 'yarn build:css'
working_dir: /app/web/themes/custom/opdavies
12 changes: 4 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
version: '2.4'

volumes:
assets:
mysql_data:
node_modules:

services:
nginx:
build:
context: .
target: nginx
volumes:
- assets:/app/web/themes/custom/opdavies/build
- node_modules:/app/web/themes/custom/opdavies/node_modules
- ./:/app
depends_on:
php:
Expand Down Expand Up @@ -46,3 +38,7 @@ services:
test: ["CMD-SHELL", "bash", "-c", "echo > /dev/tcp/localhost/3306"]
interval: 1s
restart: unless-stopped

volumes:
assets:
mysql_data:
16 changes: 15 additions & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,21 @@ function task:test:unit {

function run-tests {
# Run PHPUnit tests.
docker-compose run php --user ${DOCKER_WEB_USER} php phpunit "${@}"
docker-compose run --rm php --user ${DOCKER_WEB_USER} php phpunit "${@}"
}

function task:yarn:build:css {
# Build CSS assets, this is meant to be run from within the assets container.
local args=()

if [ "${NODE_ENV}" == "production" ]; then
args=(--minify)
else
args=(--watch)
fi

tailwindcss --postcss --input assets/css/tailwind.pcss \
--output build/app.css \ "${args[@]}"
}

eval "task:${@:-help}"
13 changes: 3 additions & 10 deletions web/themes/custom/opdavies/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "encore dev",
"prod": "npm run production",
"production": "encore production",
"watch": "encore dev --watch"
"build:css": "/app/run yarn:build:css"
},
"devDependencies": {
"@symfony/webpack-encore": "^1.1.2",
"dependencies": {
"@tailwindcss/aspect-ratio": "^0.2.0",
"@tailwindcss/forms": "^0.2.1",
"@tailwindcss/typography": "^0.4.0",
Expand All @@ -20,9 +15,7 @@
"lodash": ">=4.17.19",
"postcss": "^8.2.1",
"postcss-easy-import": "^3.0.0",
"postcss-loader": "^5.2.0",
"postcss-nested": "^5.0.5",
"tailwindcss": "^2.2.19",
"webpack-notifier": "^1.8.0"
"tailwindcss": "^2.2.19"
}
}
2 changes: 1 addition & 1 deletion web/themes/custom/opdavies/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
important: true,
purge: {
content: [
'config/**/*.yml',
'../../../../config/**/*.yml',
'tailwindcss/safelist-classes.txt',
'templates/**/*.html.twig'
],
Expand Down
27 changes: 0 additions & 27 deletions web/themes/custom/opdavies/webpack.config.js

This file was deleted.

Loading

0 comments on commit 86e9a49

Please sign in to comment.