Skip to content

Commit

Permalink
submodules + frontend + cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
lamanchy committed Sep 11, 2022
1 parent dacdc0f commit bb29442
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 80 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ local_settings.py
/frontend/public/index.html
/frontend/test/public
dj_static
/docker-compose/.dev.yaml
/docker-compose/dev_exported_config.yaml

/postgresqldata*
.venv
/venv
/.dockerignore
__pycache__
package.json
yarn.lock

/cypress/videos
/cypress/screenshots

/postgresqldata_test
.env

/.idea
/backend/old_database_dump
/backend/old_database_dump
/node_modules
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "frontend"]
path = frontend
url = [email protected]:mrkvon/bis-frontend.git
137 changes: 102 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
.PHONY: build run dev_mac dev_wsl dev_linux no_python_mac no_python_wsl no_python_linux test test_wsl clean gen_dev_dockercompose_file
.PHONY: build run dev_mac dev_wsl dev_linux no_python_mac no_python_wsl no_python_linux test test_wsl clean submodule_checkout_next submodule_update gen_dev_dockercompose_file open_cypress_wsl prepare_test_env startup_testing_backend

define with_os
if [ "$(shell uname)" = "Darwin" ]; then \
OS='mac'; \
elif grep -q icrosoft /proc/version; then \
OS='wsl'; \
else \
OS='linux'; \
fi; \
$1
endef

define with_trap
$(call with_os, bash -c "trap 'make clean' EXIT; $1")
endef


define compose_with_trap
bash -c "trap 'make clean' EXIT; docker-compose -f docker-compose.yaml -f docker-compose/dev.yaml $1"
$(call with_trap, docker-compose \
-f docker-compose.yaml \
-f docker-compose/dev.yaml $1)
endef

build: .env
build: .env submodule_sync
echo '.git' > .dockerignore
cat .gitignore >> .dockerignore
docker-compose build
Expand All @@ -14,49 +32,98 @@ build: .env
cp .example.env .env

gen_dev_dockercompose_file:
echo "# Generated dev compose config for python dev env, changes will be overridden" > docker-compose/.dev.yaml
$(call compose_with_trap, --profile python config >> docker-compose/.dev.yaml)

echo "# Generated dev compose config for python dev env, changes will be overridden" > \
docker-compose/dev_exported_config.yaml

$(call compose_with_trap, \
--profile backend config >> docker-compose/dev_exported_config.yaml)

submodule_sync:
# check all submodule directories for not-yet initialized ones and drops them,
# then sync and initialization is processed
BASE_PATH=`pwd` ; \
cat .gitmodules | grep 'path =' | cut -d ' ' -f3 | while read -r path; do \
if [ ! -f "$$BASE_PATH/$$path/.git" ]; then \
echo "initializing '$$BASE_PATH/$$path/.git'" ; \
rm -Rf $$BASE_PATH/$$path ; \
fi ; \
done ; \

git submodule sync
git submodule update --init --recursive

submodule_checkout_next:
# 1. cd to each submodule
# 2. stash all local changes
# 3. checkout branch `next`
# 4. unstash local changes back
BASE_PATH=`pwd` ; \
cat .gitmodules | grep 'path =' | cut -d ' ' -f3 | while read -r path; do \
cd $$BASE_PATH/$$path ; \
echo "entering '$$path'" ; \
git stash 2>&1 | grep -vi 'no local changes' ; \
git checkout next 2>&1 | grep -vi 'already' | grep -vi 'up to date' ; \
git stash pop 2>&1 | grep -vi 'no stash entries found' ; \
done ; \
echo "done"

submodule_update: submodule_sync
# update all submodules to their latest versions
git submodule update --init --recursive --remote

run:
docker-compose up -d

dev_mac:
$(call compose_with_trap, --profile dev up)

dev_wsl:
$(call compose_with_trap, --profile dev -f docker-compose/wsl.yaml up)

dev_linux:
$(call compose_with_trap, --profile dev -f docker-compose/linux.yaml up)
dev:
$(call compose_with_trap, \
--profile dev \
-f docker-compose/dev_$$OS.yaml up)

backend_mac:
$(call compose_with_trap, --profile backend up)
backend:
$(call compose_with_trap, \
--profile backend \
-f docker-compose/dev_$$OS.yaml up)

backend_wsl:
$(call compose_with_trap, --profile backend -f docker-compose/wsl.yaml up)
frontend:
$(call compose_with_trap, \
--profile frontned \
-f docker-compose/dev_$$OS.yaml up)

backend_linux:
$(call compose_with_trap, --profile backend -f docker-compose/linux.yaml up)
node_modules/cypress/bin/cypress:
yarn add cypress wait-on --dev

frontend_mac:
$(call compose_with_trap, --profile frontend up)

frontend_wsl:
$(call compose_with_trap, --profile frontend -f docker-compose/wsl.yaml up)

frontend_linux:
$(call compose_with_trap, --profile frontend -f docker-compose/linux.yaml up)

test:
prepare_test_env:
rm -Rf ./*data_test
$(call compose_with_trap, -f docker-compose/test.yaml run backend test)

test_wsl:
docker volume rm -f postgresqldata_test
docker volume create postgresqldata_test
rm -Rf ./*data_test
$(call compose_with_trap, -f docker-compose/test_wsl.yaml run backend test)

startup_testing_backend:
$(call with_os, \
docker-compose \
--profile backend \
-f docker-compose.yaml \
-f docker-compose/dev.yaml \
-f docker-compose/dev_test.yaml \
-f docker-compose/dev_test_$$OS.yaml up -d)

test: node_modules/cypress/bin/cypress prepare_test_env
$(call compose_with_trap, \
-f docker-compose/dev_test.yaml \
-f docker-compose/dev_test_$$OS.yaml run backend test)
$(call compose_with_trap, \
-f docker-compose/dev_test.yaml \
-f docker-compose/dev_test_$$OS.yaml run frontend test)

make prepare_test_env
make startup_testing_backend
yarn run wait-on http-get://localhost/api/
$(call with_trap, yarn run cypress run)


open_cypress: node_modules/cypress/bin/cypress prepare_test_env
make startup_testing_backend
yarn run wait-on http-get://localhost/api/
$(call with_trap, yarn run cypress open)

clean:
docker-compose down -t 0 --remove-orphans
11 changes: 11 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
specPattern: "cypress/e2e/**/*.cy.{js,jsx,ts,tsx,coffee}",
baseUrl: "http://localhost",
// setupNodeEvents(on, config) {
// // implement node event listeners here
// },
},
});
13 changes: 13 additions & 0 deletions cypress/e2e/basic.cy.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe 'Simple tests', ->
beforeEach ->
cy.clearLocalStorage()
# cy.request('api/v1/contrib/command/flush_db/')
# cy.request('api/v1/contrib/command/create_test_data/')


it 'Should pass', ->
expect(true).to.equal(true)

it 'Should load page', ->
cy.visit('/')

25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
4 changes: 2 additions & 2 deletions docker-compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ services:
nginx:
links:
- backend
# - frontend
- frontend
depends_on:
- backend
# - frontend
- frontend
volumes:
- ./nginx/certs:/etc/nginx/certs
24 changes: 12 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ services:
volumes:
- ./nginx/nginx.conf:/etc/nginx/templates/default.conf.template
- ./logs:/app/logs
# - ./frontend/build:/app/frontend
- ./frontend/build:/app/frontend
- ./backend/backend_static:/app/backend_static
- ./backend/media:/app/media

# frontend:
# container_name: bis-frontend
# build: ./frontend
# volumes:
# - ./logs:/logs
# - ./frontend:/app
# environment:
# HOST: frontend
# APP_NAME: 'bis'
# API_BASE: 'api/'
# DEBUG: 0
frontend:
container_name: bis-frontend
build: ./frontend
volumes:
- ./logs:/logs
- ./frontend:/app
environment:
HOST: frontend
APP_NAME: 'bis'
API_BASE: 'api/'
DEBUG: 0

backend:
container_name: bis-backend
Expand Down
22 changes: 11 additions & 11 deletions docker-compose/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
backend:
command: 'dev'
ports:
- 127.0.0.1:8000:8000
- 8000:8000
profiles:
- backend
- dev
Expand All @@ -17,13 +17,13 @@ services:
volumes:
- ./nginx/dev.conf:/etc/nginx/templates/default.conf.template

# frontend:
# restart: always
# command: 'dev'
# ports:
# - 3000:3000
# profiles:
# - frontend
# - dev
# environment:
# DEBUG: 1
frontend:
restart: always
command: 'dev'
ports:
- 3000:3000
profiles:
- frontend
- dev
environment:
DEBUG: 1
5 changes: 5 additions & 0 deletions docker-compose/dev_linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
nginx:
extra_hosts:
- host.docker.internal:host-gateway
1 change: 1 addition & 0 deletions docker-compose/dev_mac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: '3'
12 changes: 12 additions & 0 deletions docker-compose/dev_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
backend:
environment:
TEST: 1
ALLOWED_HOSTS: '*'
FULL_HOSTNAME: 'http://localhost'
EMAIL: '[email protected]'

postgres:
volumes:
- ./postgresqldata_test:/var/lib/postgresql/data
5 changes: 5 additions & 0 deletions docker-compose/dev_test_linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
nginx:
extra_hosts:
- host.docker.internal:host-gateway
1 change: 1 addition & 0 deletions docker-compose/dev_test_mac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: '3'
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
version: '3'
services:
backend:
environment:
ALLOWED_HOSTS: '*'

postgres:
volumes:
- postgresqldata_test:/var/lib/postgresql/data
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions docker-compose/linux.yaml

This file was deleted.

Loading

0 comments on commit bb29442

Please sign in to comment.