Skip to content

Commit

Permalink
Gh actions update (#80)
Browse files Browse the repository at this point in the history
* Update dbbackups version, use backups volumes, update nginx ports in docker compose ssl

* Use updated docker compose, drop db before restore in Makefile

* Use upated docker compose, generate .env file in github actions

* Set nginx conf to port 80
  • Loading branch information
Xpirix authored May 6, 2024
1 parent e8b98bc commit 461fda1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Generate the .env file
run: cp env.template .env

- name: Run docker-compose build
run: docker-compose -f docker-compose.dev.yml build
run: docker compose -f docker-compose.dev.yml build

- name: Run the containers
run: docker-compose -f docker-compose.dev.yml up -d postgis qgisfeed webpack
run: docker compose -f docker-compose.dev.yml up -d postgis qgisfeed webpack

- name: Wait for the containers to start
run: sleep 60

- name: Run test
run: |
docker-compose -f docker-compose.dev.yml exec -T qgisfeed python qgisfeedproject/manage.py makemigrations
docker-compose -f docker-compose.dev.yml exec -T qgisfeed python qgisfeedproject/manage.py migrate
docker-compose -f docker-compose.dev.yml exec -T qgisfeed python qgisfeedproject/manage.py test qgisfeed
docker compose -f docker-compose.dev.yml exec -T qgisfeed python qgisfeedproject/manage.py makemigrations
docker compose -f docker-compose.dev.yml exec -T qgisfeed python qgisfeedproject/manage.py migrate
docker compose -f docker-compose.dev.yml exec -T qgisfeed python qgisfeedproject/manage.py test qgisfeed
exit_code=$?
docker-compose -f docker-compose.dev.yml down
docker compose -f docker-compose.dev.yml down
exit $exit_code
45 changes: 28 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ dev-build:
@echo "------------------------------------------------------------------"
@echo "Building in development mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml build
@docker compose -f docker-compose.dev.yml build

dev-start:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in development mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml up -d
@docker compose -f docker-compose.dev.yml up -d

dev-logs:
@echo
Expand All @@ -33,42 +33,42 @@ dev-updatemigrations:
@echo "------------------------------------------------------------------"
@echo "Running makemigrations in development mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py makemigrations
@docker compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py makemigrations

dev-migrate:
@echo
@echo "------------------------------------------------------------------"
@echo "Running migrate in development mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py migrate
@docker compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py migrate

dev-dbseed:
@echo
@echo "------------------------------------------------------------------"
@echo "Seed db with JSON data from /fixtures/*.json"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py loaddata qgisfeedproject/qgisfeed/fixtures/*.json
@docker compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py loaddata qgisfeedproject/qgisfeed/fixtures/*.json

dev-createsuperuser:
@echo
@echo "------------------------------------------------------------------"
@echo "Create an admin user"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py createsuperuser
@docker compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py createsuperuser

dev-runtests:
@echo
@echo "------------------------------------------------------------------"
@echo "Running tests in development mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py test qgisfeed
@docker compose -f docker-compose.dev.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py test qgisfeed

dev-stop:
@echo
@echo "------------------------------------------------------------------"
@echo "Stopping the development server"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose.dev.yml down
@docker compose -f docker-compose.dev.yml down

# ----------------------------------------------------------------------------
# P R O D U C T I O N C O M M A N D S
Expand All @@ -79,54 +79,65 @@ build:
@echo "------------------------------------------------------------------"
@echo "Building in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml build
@docker compose -f docker-compose-production-ssl.yml build

start:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml up -d
@docker compose -f docker-compose-production-ssl.yml up -d

dbrestore:
@echo
@echo "------------------------------------------------------------------"
@echo "Restore dump from /backups/latest-qgisfeed.dmp and /backups/latest-metabase.dmp in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "pg_restore -c /backups/latest-qgisfeed.dmp -d qgisfeed"
@docker-compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "pg_restore -c /backups/latest-metabase.dmp -d metabase"
@echo "stopping qgisfeed container"
@docker compose -f docker-compose-production-ssl.yml stop qgisfeed
@echo "Dropping the gis and metabase databases"
-@docker compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "dropdb --force qgisfeed"
-@docker compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "dropdb --force metabase"
@echo "Creating the qgisfeed and metabase databases"
-@docker compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "createdb -O docker -T template1 qgisfeed"
-@docker compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "createdb -O docker -T template1 metabase"
@echo "Restore database from backups/latest-qgisfeed.dmp and backups/latest-metabase.dmp"
@docker compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "pg_restore -c /backups/latest-qgisfeed.dmp -d qgisfeed"
@docker compose -f docker-compose-production-ssl.yml exec postgis su - postgres -c "pg_restore -c /backups/latest-metabase.dmp -d metabase"
@echo "Starting qgisfeed container"
@docker compose -f docker-compose-production-ssl.yml up -d qgisfeed

updatemigrations:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py makemigrations
@docker compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py makemigrations

migrate:
@echo
@echo "------------------------------------------------------------------"
@echo "Running migrate in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py migrate
@docker compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py migrate

createsuperuser:
@echo
@echo "------------------------------------------------------------------"
@echo "Create an admin user"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py createsuperuser
@docker compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py createsuperuser

collectstatic:
@echo
@echo "------------------------------------------------------------------"
@echo "Collecting static in production mode"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py collectstatic --noinput
@docker compose -f docker-compose-production-ssl.yml exec $(CONTAINER_NAME) python qgisfeedproject/manage.py collectstatic --noinput

stop:
@echo
@echo "------------------------------------------------------------------"
@echo "Stop the production server"
@echo "------------------------------------------------------------------"
@docker-compose -f docker-compose-production-ssl.yml down
@docker compose -f docker-compose-production-ssl.yml down
2 changes: 1 addition & 1 deletion config/nginx/qgisfeed.conf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ server {
proxy_set_header X-Forwarded-Port $server_port;
}

listen 8000;
listen 80;
server_name feed.qgis.org www.feed.qgis.org;
}
4 changes: 2 additions & 2 deletions config/nginx/ssl/qgisfeed.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# portal
server {
listen 8000;
listen [::]:8000;
listen 80;
listen [::]:80;
server_name feed.qgis.org;

# Block *.php
Expand Down
13 changes: 7 additions & 6 deletions docker-compose-production-ssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
postgis:
image: kartoza/postgis:16-3.4
ports:
- "5432"
- "5432"
environment:
POSTGRES_USER: ${QGISFEED_DOCKER_DBUSER}
POSTGRES_PASS: ${QGISFEED_DOCKER_DBPASSWORD}
Expand All @@ -20,6 +20,7 @@ services:
test: "POSTGRES_PASS=$${QGISFEED_DOCKER_DBPASSWORD} pg_isready -h 127.0.0.1 -U ${QGISFEED_DOCKER_DBUSER} -d ${QGISFEED_DOCKER_DBNAME}"
volumes:
- ${QGISFEED_DOCKER_SHARED_VOLUME}:/var/lib/postgresql
- ${QGISFEED_BACKUP_VOLUME}:/backups
networks:
internal:

Expand Down Expand Up @@ -67,7 +68,7 @@ services:
EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD}
command: /code/entrypoint_production.sh
expose:
- "8000"
- "8000"
volumes:
- ${QGISFEED_DOCKER_SHARED_VOLUME}:/shared-volume
- ../qgis-feed:/code
Expand All @@ -85,8 +86,8 @@ services:
nginx:
image: nginx:latest
ports:
- "80:8000"
- "443:443"
- "80:80"
- "443:443"
logging:
driver: "json-file"
options:
Expand All @@ -113,9 +114,9 @@ services:
depends_on:
- nginx
command: certonly --webroot --webroot-path=/var/www/webroot --email [email protected] --agree-tos --no-eff-email --force-renewal -d feed.qgis.org

dbbackups:
image: kartoza/pg-backup:11.0
image: kartoza/pg-backup:16-3.4
environment:
DUMPPREFIX: PG_QGIS_FEED
POSTGRES_DATABASE: ${QGISFEED_DOCKER_DBNAME}
Expand Down

0 comments on commit 461fda1

Please sign in to comment.