Skip to content

Commit

Permalink
Fix docker tests; upgrade to docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieucan committed Apr 17, 2024
1 parent 568fd48 commit 346fdf2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ Build and test:
services:
- docker:dind
before_script:
- apk add black py3-flake8 py3-isort docker-compose make
- apk add black py3-flake8 py3-isort make
script:
- cd contrib/docker
- make build
- docker compose up -d db
- make update-db
- make test-all
- cd ../..
Expand Down
22 changes: 10 additions & 12 deletions contrib/docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
DOCKER_EXEC = docker exec
CONTAINER = docker_debsources_1
MAKE = make -C /opt/debsources/
TEST_TARGETS = test test-all test-fast test-slow test-coverage
SRC_TARGETS = all doc check clean test-online-app

.PHONY: build update-db run attach init-db $(SRC_TARGETS) $(TEST_TARGETS)

build:
docker-compose build --pull
docker compose build --pull

update-db:
docker-compose run debsources /opt/db-update
docker compose run app /opt/db-update

run:
docker-compose up -d
docker compose up -d

logs:
docker logs -f docker_debsources_1
docker compose logs app

stop:
docker-compose stop
docker compose stop

start-apache:
$(DOCKER_EXEC) -it $(CONTAINER) apache2ctl start
docker compose exec -it app apache2ctl start

attach:
$(DOCKER_EXEC) -it $(CONTAINER) /bin/bash
docker compose exec -it app /bin/bash

init-db:
$(DOCKER_EXEC) $(CONTAINER) /opt/db-init
docker compose exec app /opt/db-init

$(SRC_TARGETS):
$(DOCKER_EXEC) $(CONTAINER) $(MAKE) $@
docker compose exec app $(MAKE) $@

$(TEST_TARGETS): run init-db
$(DOCKER_EXEC) $(CONTAINER) $(MAKE) $@
docker compose exec app $(MAKE) $@
2 changes: 1 addition & 1 deletion contrib/docker/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# preferred.

[DEFAULT]
db_uri: postgresql://docker:docker@db_1:5432/debsources
db_uri: postgresql://docker:docker@db:5432/debsources
root_dir: /opt/debsources
cache_dir: %(root_dir)s/testdata/cache
local_dir: %(root_dir)s/local
Expand Down
44 changes: 23 additions & 21 deletions contrib/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
db:
image: postgres:11
environment:
POSTGRES_USER: docker
POSTGRES_PASSWORD: docker
POSTGRES_DB: debsources
name: debsources

debsources:
build: .
ports:
- "5000:5000"
- "5001:80"
volumes:
- "../../:/opt/debsources"
links:
- db
environment:
PGUSER: docker
PGPASSWORD: docker
PGHOST: db_1
working_dir: /opt/debsources
command: /opt/run-web
services:
db:
image: postgres:11
environment:
POSTGRES_USER: docker
POSTGRES_PASSWORD: docker
POSTGRES_DB: debsources

app:
build: .
ports:
- "5000:5000"
- "5001:80"
volumes:
- "../../:/opt/debsources"
environment:
PGUSER: docker
PGPASSWORD: docker
PGHOST: db
PGPORT: 5432
working_dir: /opt/debsources
command: /opt/run-web
4 changes: 2 additions & 2 deletions contrib/docker/scripts/db-init
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

echo "Waiting for PostgreSQL to launch on 5432..."
while ! nc -z db_1 5432; do
while ! nc -z ${PGHOST} ${PGPORT}; do
sleep 0.1
done
echo "PostgreSQL launched"

echo "Creating Debsources DB schema..."
/opt/debsources/bin/debsources-dbadmin --createdb postgresql://docker:docker@db_1:5432/debsources
/opt/debsources/bin/debsources-dbadmin --createdb postgresql://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/debsources
echo "Debsources DB schema created"
4 changes: 2 additions & 2 deletions doc/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ You can run debsources test suite in a docker container using the following
commands (containers must be running):

$ cd contrib/docker
$ docker-compose build
$ docker-compose run debsources /opt/run-tests
$ docker compose build
$ docker compose run app /opt/run-tests

Test attributes
---------------
Expand Down

0 comments on commit 346fdf2

Please sign in to comment.