diff --git a/.env b/.env index ab1510e5..06d6e2fc 100644 --- a/.env +++ b/.env @@ -6,6 +6,9 @@ TRAEFIK_PUBLIC_NETWORK=traefik-public TRAEFIK_TAG=cic.net TRAEFIK_PUBLIC_TAG=traefik-public +TAG=localhost +FRONTEND_ENV=dev + # Flower FLOWER_BASIC_AUTH=admin:changethis diff --git a/README.md b/README.md index 12f0fb88..c86ab82f 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,20 @@ docker-compose logs backend If your Docker is not running in `localhost` (the URLs above wouldn't work) check the sections below on **Development with Docker Toolbox** and **Development with a custom IP**. +#### Deploy the stack locally + +If you want to run the docker stack locally on swarm + +``` + docker-compose -f docker-compose.yml -f docker-compose.override.yml config > docker-stack.yml +``` + +``` +docker node update z1ehkrw1mvqlxc2udwt4xpype --label-add cic-net.app-db-data=true + docker stack deploy -c docker-stack.yml cic-net +``` + + ## Backend local development, additional details **fill me in** @@ -77,83 +91,14 @@ You should see an output like: root@7f2607af31c3:/app# ``` -that means that you are in a `bash` session inside your container, as a `root` user, under the `/app` directory. -There you can use the script `/start-reload.sh` to run the debug live reloading server. You can run that script from inside the container with: - -```console -$ bash /start-reload.sh -``` - -...it will look like: - -```console -root@7f2607af31c3:/app# bash /start-reload.sh -``` - -and then hit enter. That runs the live reloading server that auto reloads when it detects code changes. - -Nevertheless, if it doesn't detect a change but a syntax error, it will just stop with an error. But as the container is still alive and you are in a Bash session, you can quickly restart it after fixing the error, running the same command ("up arrow" and "Enter"). - -...this previous detail is what makes it useful to have the container alive doing nothing and then, in a Bash session, make it run the live reload server. - -### Backend tests - -To test the backend run: - -```console -$ DOMAIN=backend sh ./scripts/test.sh -``` - -The file `./scripts/test.sh` has the commands to generate a testing `docker-stack.yml` file, start the stack and test it. - -The tests run with Pytest, modify and add tests to `./backend/app/app/tests/`. - -If you use GitLab CI the tests will run automatically. - -#### Local tests - -Start the stack with this command: - -```Bash -DOMAIN=backend sh ./scripts/test-local.sh -``` -The `./backend/app` directory is mounted as a "host volume" inside the docker container (set in the file `docker-compose.dev.volumes.yml`). -You can rerun the test on live code: - -```Bash -docker-compose exec backend /app/tests-start.sh -``` #### Test running stack If your stack is already up and you just want to run the tests, you can use: ```bash -docker-compose exec backend /app/tests-start.sh +docker-compose exec data-seeding /script/run_ussd_user_imports.sh ``` -That `/app/tests-start.sh` script just calls `pytest` after making sure that the rest of the stack is running. If you need to pass extra arguments to `pytest`, you can pass them to that command and they will be forwarded. - -For example, to stop on first error: - -```bash -docker-compose exec backend bash /app/tests-start.sh -x -``` - -#### Test Coverage - -Because the test scripts forward arguments to `pytest`, you can enable test coverage HTML report generation by passing `--cov-report=html`. - -To run the local tests with coverage HTML reports: - -```Bash -DOMAIN=backend sh ./scripts/test-local.sh --cov-report=html -``` - -To run the tests in a running stack with coverage HTML reports: - -```bash -docker-compose exec backend bash /app/tests-start.sh --cov-report=html -``` diff --git a/apps/cic-staff-client/Dockerfile b/apps/cic-staff-client/Dockerfile index 9721319c..e12f89d2 100644 --- a/apps/cic-staff-client/Dockerfile +++ b/apps/cic-staff-client/Dockerfile @@ -8,8 +8,10 @@ WORKDIR /app COPY package*.json . COPY patch-webpack.js . -RUN npm install # copying rest of project +RUN --mount=type=cache,target=/app/.npm \ + npm set cache /app/.npm && \ + npm ci COPY . . diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 40d4c15b..54f8640c 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -65,6 +65,10 @@ services: build: args: FRONTEND_ENV: dev + target: build + command: npm run start:dev + volumes: + - ./apps/cic-staff-client:/app/ labels: - traefik.enable=true - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set} @@ -81,6 +85,7 @@ services: - traefik.http.services.${STACK_NAME?Variable not set}-cache.loadbalancer.server.port=63313 cic-meta-server: + image: $REGISTRY:$TAG ports: - ${HTTP_PORT_CIC_META:-63380}:8000 #depends_on: diff --git a/docker-compose.yml b/docker-compose.yml index a74b0517..f571929a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,10 @@ networks: # Allow setting it to false for testing external: ${TRAEFIK_PUBLIC_NETWORK_IS_EXTERNAL-true} +configs: + create_db: + external: true + services: proxy: image: traefik:v2.2 @@ -132,7 +136,7 @@ services: volumes: - postgres-db:/var/lib/postgresql/data configs: - - source: create_db.sql + - source: create_db target: /docker-entrypoint-initdb.d/1-create_all_db.sql deploy: placement: