Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker configuration #102

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.git/
docs/
cache/
bin/
var/
lib/
include/
share/
develop-eggs/
parts/
.installed.cfg
.mr.developer.cfg
src/collective/taxonomy/javascripts/node_modules/
src/collective/taxonomy/javascripts/cypress/videos/
src/collective/taxonomy/javascripts/cypress/screenshots/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ share/
include/
lib/
share/
cache/
src/collective/taxonomy/javascripts/cypress/videos/
src/collective/taxonomy/javascripts/cypress/screenshots/
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Plone + make + virtualenv
FROM plone:5.2.1
ARG DEBIAN_FRONTEND=noninteractive

COPY . /plone/app

RUN apt-get update -qy \
&& apt-get install -qy \
make \
&& pip install -q virtualenv==16.7.9 \
&& mkdir /plone/.buildout \
&& echo "[buildout]" > /plone/.buildout/default.cfg \
&& echo "download-cache = /app/cache/downloads" >> /plone/.buildout/default.cfg \
&& echo "eggs-directory = /app/cache/eggs" >> /plone/.buildout/default.cfg \
&& mkdir /app \
&& ln -sf /plone/buildout-cache /app/cache \
&& usermod -u 1000 plone \
&& groupmod -g 1000 plone \
&& chown -R plone:plone /plone \
&& chown -R plone:plone /app \
&& su - plone -c 'cd /plone/app && make build-backend' \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /plone/buildout-cache/downloads/*

USER plone
VOLUME /app
WORKDIR /plone/app
ENTRYPOINT ["/usr/bin/make"]
CMD ["start-backend"]
46 changes: 26 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SHELL := /bin/bash
# Run test if not on Travis or Python 3 and Plone 5.2
NOT_TRAVIS_OR_PYTHON3_PLONE52 := $(shell if [ -z "$$TRAVIS" ] || ([ "$$PLONE_VERSION" == "5.2" ] && [ "$$TRAVIS_PYTHON_VERSION" == "3.7" ]); then echo "true"; else echo "false"; fi)
VIRTUALENV_NOT_INSTALLED := $(shell if [ ! -d bin ]); then echo "true"; else echo "false"; fi)

version = 3

Expand All @@ -25,11 +26,13 @@ build: build-backend build-frontend ## Build

build-backend:
@echo "$(GREEN)==> Setup Build$(RESET)"
ifeq ("$(VIRTUALENV_NOT_INSTALLED)", "true")
virtualenv --clear --python=python3 .
bin/pip install --upgrade pip
bin/pip install -r requirements.txt
ifeq ("$(NOT_TRAVIS_OR_PYTHON3_PLONE52)", "true")
bin/pip install black
endif
endif
bin/buildout

Expand All @@ -45,12 +48,15 @@ start: ## Start
split-window -h "make start-frontend" \; \
select-pane -t 0; \
else \
make start-backend; \
make start-backend-development; \
fi

start-backend:
@echo "$(GREEN)==> Start Plone Backend$(RESET)"
NODE_ENV=development bin/instance fg
bin/instance fg

start-backend-development:
NODE_ENV=development make start-backend

start-frontend:
@echo "$(GREEN)==> Start Webpack Watcher$(RESET)"
Expand All @@ -63,38 +69,35 @@ start-cypress: ## Start Cypress
cd src/collective/taxonomy/javascripts && yarn run cypress open
bin/instance stop

.PHONY: Test
test: code-format-check code-analysis test-backend test-frontend test-cypress ## Test

.PHONY: Code Format Check
code-format-check: code-format-check-backend code-format-check-frontend ## Code Format Check
lint: lint-backend lint-frontend ## Code Format Check

code-format-check-backend:
lint-backend:
@echo "$(GREEN)==> Run Python code format check$(RESET)"
ifeq ("$(NOT_TRAVIS_OR_PYTHON3_PLONE52)", "true")
bin/black --check src/
bin/code-analysis
endif

code-format-check-frontend:
lint-frontend:
@echo "$(GREEN)==> Run Javascript code format check$(RESET)"
cd src/collective/taxonomy/javascripts && yarn prettier

.PHONY: Code Format
code-format: code-format-backend code-format-frontend ## Code Format
.PHONY: Code Format Fixes
lint-fix: lint-fix-backend lint-fix-frontend ## Code Format Fixes

code-format-backend:
@echo "$(GREEN)==> Run Python code format$(RESET)"
lint-fix-backend:
@echo "$(GREEN)==> Run Python code format fix$(RESET)"
ifeq ("$(NOT_TRAVIS_OR_PYTHON3_PLONE52)", "true")
bin/black src/
endif

code-format-frontend:
@echo "$(GREEN)==> Run Javascript code format$(RESET)"
lint-fix-frontend:
@echo "$(GREEN)==> Run Javascript code format fix$(RESET)"
cd src/collective/taxonomy/javascripts && yarn prettier:fix

code-analysis:
@echo "$(green)==> Run static code analysis$(reset)"
ifeq ("$(NOT_TRAVIS_OR_PYTHON3_PLONE52)", "true")
bin/code-analysis
endif
.PHONY: Test
test: lint test-backend test-frontend test-cypress ## Test

test-backend:
@echo "$(GREEN)==> Run Backend Tests$(RESET)"
Expand All @@ -121,6 +124,9 @@ test-cypress-foreground:
.PHONY: Clean
clean: ## Clean
@echo "$(RED)==> Cleaning environment and build$(RESET)"
git clean -Xdf
rm -rf bin lib include share develop-eggs parts .installed.cfg .mr.developer.cfg
cd src/collective/taxonomy/javascripts && rm -rf node_modules yarn*

include Makefile.docker

.PHONY: all clean
85 changes: 85 additions & 0 deletions Makefile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
NAME='collective/collective.taxonomy:2.0.1'

.PHONY: Build with Docker
docker-build: docker-build-backend docker-build-frontend ## Build with Docker

docker-build-backend:
@echo "$(GREEN)==> Setup Build with Docker$(RESET)"
if [[ "$$(docker images -q $(NAME) 2> /dev/null)" == "" ]]; then \
docker build -t $(NAME) . ; \
fi
if [ ! -d cache ]; then \
mkdir -p cache/eggs cache/downloads/list cache/extends; \
docker-compose run --rm backend "cd /app/cache/eggs && find /plone/buildout-cache/eggs/* -maxdepth 0 -type d -exec ln -sf {} . \;" || true ; \
fi
docker-compose run --rm backend "make build-backend"

build-frontend-docker:
@echo "$(GREEN)==> Build Frontend$(RESET)"
cd src/collective/taxonomy/javascripts && yarn --network-timeout 30000
cd src/collective/taxonomy/javascripts && yarn build

docker-build-frontend:
@echo "$(GREEN)==> Build Frontend with Docker$(RESET)"
mkdir -p cache/npm cache/yarn cache/cypress
docker-compose run --rm frontend "make build-frontend-docker"

.PHONY: Start with Docker
docker-start: ## Start with Docker
@echo "$(GREEN)==> Start Plone and Webpack watcher with Docker$(RESET)"
docker-compose up

.PHONY: Code Format Check with Docker
docker-lint: docker-lint-backend docker-lint-frontend ## Code Format Check with Docker

docker-lint-backend:
@echo "$(GREEN)==> Run Python code format check with Docker$(RESET)"
docker-compose run --rm backend "make lint-backend"

docker-lint-frontend:
@echo "$(GREEN)==> Run Javascript code format check with Docker$(RESET)"
docker-compose run --rm frontend "make lint-frontend"

.PHONY: Code Format Fixes with Docker
docker-lint-fix: docker-lint-fix-backend docker-lint-fix-frontend ## Code Format Fixes with Docker

docker-lint-fix-backend:
@echo "$(GREEN)==> Run Python code format fix with Docker$(RESET)"
docker-compose run --rm backend "make lint-fix-backend"

docker-lint-fix-frontend:
@echo "$(GREEN)==> Run Javascript code format fix with Docker$(RESET)"
docker-compose run --rm frontend "make lint-fix-frontend"

.PHONY: Test
docker-test: docker-lint docker-test-backend docker-test-frontend docker-test-cypress ## Test

docker-test-backend:
@echo "$(GREEN)==> Run Backend Tests with Docker$(RESET)"
docker-compose run --rm backend "make test-backend"

docker-test-frontend:
@echo "$(GREEN)==> Run Frontend Tests with Docker$(RESET)"
docker-compose run --rm frontend "make test-frontend"

test-cypress-docker:
while ! curl -sf http://frontend:3000 > /dev/null; do sleep 1; done
while ! curl -sf http://backend:8080/Plone > /dev/null; do sleep 1; done
cd src/collective/taxonomy/javascripts && yarn run cypress run

docker-test-cypress:
@echo "$(GREEN)==> Run Cypress Test with Docker$(RESET)"
docker-compose up -d
docker-compose exec frontend make test-cypress-docker
docker-compose down

docker-clean-image:
if [[ "$$(docker images -q $(NAME) 2> /dev/null)" != "" ]]; then \
docker image rm $(NAME) ; \
fi

docker-clean:
@echo "$(RED)==> Cleaning Docker environment$(RESET)"
rm -rf cache
docker-compose down
make clean
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '2'
services:
frontend:
image: cypress/base:12.18.0
user: 1000:1000
ports:
- 3000:3000
volumes:
- .:/app
environment:
- npm_config_cache=/app/cache/npm
- npm_config_global=true
- YARN_CACHE_FOLDER=/app/cache/yarn
- CYPRESS_CACHE_FOLDER=/app/cache/cypress
- CYPRESS_VIDEO=false
- CYPRESS_baseUrl=http://backend:8080/Plone
working_dir: /app
entrypoint: /bin/sh -c
command:
- make start-frontend
backend:
image: collective/collective.taxonomy:2.0.1
user: 1000:1000
ports:
- 8080:8080
volumes:
- .:/app
working_dir: /app
entrypoint: /bin/sh -c
command:
- make start-backend-development
4 changes: 2 additions & 2 deletions src/collective/taxonomy/javascripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'index.html'))
})

app.listen(3000, 'localhost', function (err) {
app.listen(3000, '0.0.0.0', function (err) {
if (err) {
console.log(err)
return
}

console.log('Listening at http://localhost:3000')
console.log('Listening at http://0.0.0.0:3000')
})