Skip to content

Commit

Permalink
fix: Refactor Docker commands in scripts (#1282)
Browse files Browse the repository at this point in the history
Update the Docker commands in the scripts to use the "docker compose" syntax instead of "docker-compose".
  • Loading branch information
drikusroor authored Sep 24, 2024
1 parent 1ddfcc4 commit 3490098
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 43 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Run Backend Tests
run: sudo docker-compose --env-file .env-github-actions run server bash -c "coverage run manage.py test"
run: sudo docker compose --env-file .env-github-actions run server bash -c "coverage run manage.py test"
- name: Generate Backend Coverage Report (Inline)
run: sudo docker-compose --env-file .env-github-actions run server bash -c "coverage report --show-missing"
run: sudo docker compose --env-file .env-github-actions run server bash -c "coverage report --show-missing"

# Generate coverage badge (only for main and develop branches)
- name: Generate Backend Coverage Report (XML) and Badge
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
run: |
sudo docker-compose --env-file .env-github-actions run server bash -c "coverage xml"
sudo docker-compose --env-file .env-github-actions run server bash -c "genbadge coverage -i coverage.xml -o coverage-backend-badge-new.svg -n \"Backend Code Coverage\""
sudo docker compose --env-file .env-github-actions run server bash -c "coverage xml"
sudo docker compose --env-file .env-github-actions run server bash -c "genbadge coverage -i coverage.xml -o coverage-backend-badge-new.svg -n \"Backend Code Coverage\""
# Push coverage badge to separate branch (only for main and develop branches)
- name: Push Backend Coverage Badge to separate branch
continue-on-error: true
Expand Down Expand Up @@ -55,15 +55,15 @@ jobs:
- uses: actions/checkout@v3
- name: Lint Backend
continue-on-error: false
run: sudo docker-compose --env-file .env-github-actions run server bash -c "flake8"
run: sudo docker compose --env-file .env-github-actions run server bash -c "flake8"

frontend-test:
name: Test Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Frontend Tests
run: sudo docker-compose --env-file .env-github-actions run client yarn test:ci
run: sudo docker compose --env-file .env-github-actions run client yarn test:ci

frontend-coverage-badge:
name: Generate Frontend Coverage Badge
Expand All @@ -74,8 +74,8 @@ jobs:
- uses: actions/checkout@v3
- name: Generate Frontend Coverage Report (XML) and Badge
run: |
sudo docker-compose --env-file .env-github-actions run client yarn test:ci
sudo docker-compose --env-file .env-github-actions run client yarn coverage-badges -s public/coverage/coverage-summary.json -o public/coverage/coverage-frontend-badge-new.svg --label 'Frontend Code Coverage'
sudo docker compose --env-file .env-github-actions run client yarn test:ci
sudo docker compose --env-file .env-github-actions run client yarn coverage-badges -s public/coverage/coverage-summary.json -o public/coverage/coverage-frontend-badge-new.svg --label 'Frontend Code Coverage'
- name: Push Frontend Coverage Badge to separate branch
continue-on-error: true
run: |
Expand Down Expand Up @@ -106,4 +106,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo docker-compose --env-file .env-github-actions run client yarn lint
- run: sudo docker compose --env-file .env-github-actions run client yarn lint
28 changes: 14 additions & 14 deletions .github/workflows/podman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ jobs:
echo "VITE_SENTRY_DSN=$FRONTEND_SENTRY_DSN" >> .env
cp .env frontend/.env
- name: Build Podman images
run: podman-compose -f docker-compose-deploy.yml build
run: podman-compose -f docker compose-deploy.yml build
- name: Shut down running containers
run: podman compose -f docker-compose-deploy.yml down
run: podman compose -f docker compose-deploy.yml down
- name: Deploy Podman images
run: podman-compose -f docker-compose-deploy.yml up -d
run: podman-compose -f docker compose-deploy.yml up -d
- name: Notify Sentry of new release
run: |
curl -X POST "https://sentry.io/api/0/organizations/uva-aml/releases/" \
Expand All @@ -101,9 +101,9 @@ jobs:
- name: Prune old images
run: podman image prune -a -f
- name: Check Podman images
run: podman-compose -f docker-compose-deploy.yml ps
run: podman-compose -f docker compose-deploy.yml ps
- name: Check logs
run: podman-compose -f docker-compose-deploy.yml logs
run: podman-compose -f docker compose-deploy.yml logs

deploy-acceptance:
name: Deploy to acceptance environment
Expand Down Expand Up @@ -171,11 +171,11 @@ jobs:
echo "VITE_SENTRY_DSN=$FRONTEND_SENTRY_DSN" >> .env
cp .env frontend/.env
- name: Build Podman images
run: podman-compose -f docker-compose-deploy.yml build
run: podman-compose -f docker compose-deploy.yml build
- name: Shut down running containers
run: podman compose -f docker-compose-deploy.yml down
run: podman compose -f docker compose-deploy.yml down
- name: Deploy Podman images
run: podman-compose -f docker-compose-deploy.yml up -d
run: podman-compose -f docker compose-deploy.yml up -d
- name: Notify Sentry of new release
run: |
curl -X POST "https://sentry.io/api/0/organizations/uva-aml/releases/" \
Expand All @@ -193,9 +193,9 @@ jobs:
- name: Prune old images
run: podman image prune -a -f
- name: Check Podman images
run: podman-compose -f docker-compose-deploy.yml ps
run: podman-compose -f docker compose-deploy.yml ps
- name: Check logs
run: podman-compose -f docker-compose-deploy.yml logs
run: podman-compose -f docker compose-deploy.yml logs

deploy-production:
name: Deploy to production environment
Expand Down Expand Up @@ -260,11 +260,11 @@ jobs:
echo "VITE_SENTRY_DSN=$FRONTEND_SENTRY_DSN" >> .env
cp .env frontend/.env
- name: Build Podman images
run: podman-compose -f docker-compose-deploy.yml build
run: podman-compose -f docker compose-deploy.yml build
- name: Shut down running containers
run: podman compose -f docker-compose-deploy.yml down
run: podman compose -f docker compose-deploy.yml down
- name: Deploy Podman images
run: podman-compose -f docker-compose-deploy.yml up -d
run: podman-compose -f docker compose-deploy.yml up -d
- name: Notify Sentry of new release
run: |
curl -X POST "https://sentry.io/api/0/organizations/uva-aml/releases/" \
Expand All @@ -282,7 +282,7 @@ jobs:
- name: Prune old images
run: podman image prune -a -f
- name: Check Podman images
run: podman-compose -f docker-compose-deploy.yml ps
run: podman-compose -f docker compose-deploy.yml ps

e2e-acceptance:
name: E2E tests on acceptance environment
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ Install [Docker Desktop](https://docs.docker.com/desktop/).
Make a copy of [the file](https://github.com/Amsterdam-Music-Lab/MUSCLE/blob/develop/.env.dist) `.env.dist` (in the same directory as this README) and rename it to `.env.` This file contains variables used by Docker to start up a container network serving MUSCLE.

Start Docker (the app icon is a whale carrying containers). Then, open a terminal and run
`docker-compose up` (add `sudo` on Linux).
This command starts up the containers defined in `docker-compose.yaml`:
`docker compose up` (add `sudo` on Linux).
This command starts up the containers defined in `docker compose.yaml`:
- a PostgreSQL container, for storing experiment/user/playlist data, saved on the host machine in the Docker user data, represented in the volume `db_data`. Data added to the database will persist if the container is shut down.
- a ip2country container, which provides country codes for ip addresses, used for demographic information of users.
- a container of the server, defined in DockerfileDevelop in `backend`. The Dockerfile defines the Python version and installs development dependencies. The startup command runs migrations and then starts up a Django development server.
- a container of the client, defined in DockerfileDevelop in `frontend`. The Dockerfile defines the node version and installs node modules. The startup command kicks off a React development server.

Once you see all containers have started up, open your browser and navigate to [localhost:3000](http://localhost:3000). You should now be able to see the first screen of the Goldsmiths Musical Sophistication Index questionnaire.

Since the `docker-compose.yaml` defines bind mounts for `backend` and `frontend`, any changes to the files on the host are immediately reflected in the containers, which means code watching works and hot reload works in the same way as with a native node or Django server.
Since the `docker compose.yaml` defines bind mounts for `backend` and `frontend`, any changes to the files on the host are immediately reflected in the containers, which means code watching works and hot reload works in the same way as with a native node or Django server.

To stop the containers, press `ctrl-c` or (in another terminal) run
`docker-compose down`.
`docker compose down`.

## Production build
A production build should define its own `docker-compose.yaml`, making use of the `Dockerfile` of the `backend` and `frontend` environments. It should also define a custom .env file, with safe passwords for the SQL database and the Python backend. Instead of mounting the entire backend and frontend directory and using the development servers, the backend should serve with gunicorn, and the frontend should use a build script to compile static html, css and JavaScript.
A production build should define its own `docker compose.yaml`, making use of the `Dockerfile` of the `backend` and `frontend` environments. It should also define a custom .env file, with safe passwords for the SQL database and the Python backend. Instead of mounting the entire backend and frontend directory and using the development servers, the backend should serve with gunicorn, and the frontend should use a build script to compile static html, css and JavaScript.

## Troubleshooting

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Docker-compose definition for development
# docker compose definition for development

version: '2.4'

Expand Down
3 changes: 1 addition & 2 deletions scripts/build-front
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
docker-compose run --rm client yarn build

docker compose run --rm client yarn build
2 changes: 1 addition & 1 deletion scripts/lint-back
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker-compose run --rm server bash -c "flake8"
docker compose run --rm server bash -c "flake8"
2 changes: 1 addition & 1 deletion scripts/lint-front
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker-compose run --rm client yarn lint $@
docker compose run --rm client yarn lint $@
2 changes: 1 addition & 1 deletion scripts/manage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

# This script executes Django management commands through Docker.
docker-compose run --rm server python manage.py $@
docker compose run --rm server python manage.py $@
3 changes: 1 addition & 2 deletions scripts/test-back
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
docker-compose run --rm server bash -c "python manage.py test $@"

docker compose run --rm server bash -c "python manage.py test $@"
3 changes: 1 addition & 2 deletions scripts/test-back-coverage
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
docker-compose run --rm server bash -c "coverage run manage.py test && coverage report --show-missing"

docker compose run --rm server bash -c "coverage run manage.py test && coverage report --show-missing"
3 changes: 1 addition & 2 deletions scripts/test-front
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
docker-compose run --rm client yarn test --watch=false

docker compose run --rm client yarn test --watch=false
2 changes: 1 addition & 1 deletion scripts/test-front-ci
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker-compose run --rm client yarn test:ci
docker compose run --rm client yarn test:ci
3 changes: 1 addition & 2 deletions scripts/test-front-watch
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
docker-compose run --rm client yarn test --watch=true

docker compose run --rm client yarn test --watch=true

0 comments on commit 3490098

Please sign in to comment.