Skip to content

Commit 8521c76

Browse files
committed
Switch database server to PostgreSQL 13
1 parent c45e69d commit 8521c76

File tree

12 files changed

+39
-45
lines changed

12 files changed

+39
-45
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818
- run: docker-compose up -d
19-
- name: Wait for MySQL
19+
- name: Wait for PostgreSQL
2020
run: |
2121
set +e
2222
for i in {0..60}; do
23-
docker-compose exec -T chris_store_dev_db mysqladmin -uroot -prootp status 2> /dev/null
23+
docker-compose exec -T chris_store_dev_db psql -U chris -d chris_store_dev -c "select 1" 2> /dev/null
2424
if [ "$?" = "0" ]; then
2525
dbup=y
2626
break
@@ -29,11 +29,9 @@ jobs:
2929
echo .
3030
done
3131
if [ "$dbup" != "y" ]; then
32-
echo "::error ::Timed out waiting for MySQL database."
32+
echo "::error ::Timed out waiting for PostgreSQL database."
3333
exit 1
3434
fi
35-
- name: Prepare MySQL for tests
36-
run: docker-compose exec -T chris_store_dev_db mysql -uroot -prootp -e 'GRANT ALL PRIVILEGES ON *.* TO "chris"@"%"'
3735
- name: Run all tests
3836
run: docker-compose exec -T chris_store_dev python manage.py test
3937
- run: docker-compose down -v

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ RUN apt-get update \
4949
&& export LC_ALL=en_US.UTF-8 \
5050
&& locale-gen en_US.UTF-8 \
5151
&& dpkg-reconfigure locales \
52-
&& apt-get install -y libssl-dev libmysqlclient-dev \
52+
&& apt-get install -y libssl-dev libpq-dev \
5353
&& apt-get install -y apache2 apache2-dev \
54-
&& pip install --upgrade pip \
55-
&& pip install -r ${REQPATH}/${ENVIRONMENT}.txt \
54+
&& pip install --upgrade pip \
55+
&& pip install -r ${REQPATH}/${ENVIRONMENT}.txt \
5656
&& useradd -l -u $UID -ms /bin/bash localuser
5757

5858
# Start as user localuser

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
![License][license-badge]
44
![Last Commit][last-commit-badge]
55

6-
Back end for the ChRIS store. This is a Django-MySQL project that houses descriptions of ChRIS plugin-apps and workflows for registering to a ChRIS CUBE instance.
6+
Back end for the ChRIS store. This is a Django-PostgreSQL project that houses descriptions of ChRIS plugin-apps and workflows for registering to a ChRIS CUBE instance.
77

88
## ChRIS store development, testing and deployment
99

docker-compose_dev.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ services:
3535
role: "Development server"
3636

3737
chris_store_dev_db:
38-
image: mysql:8
39-
command: --collation-server=utf8mb4_0900_as_cs
38+
image: postgres:13
4039
volumes:
41-
- chris_store_dev_db_data:/var/lib/mysql:z
40+
- chris_store_dev_db_data:/var/lib/postgresql/data:z
4241
environment:
43-
- MYSQL_ROOT_PASSWORD=rootp
44-
- MYSQL_DATABASE=chris_store_dev
45-
- MYSQL_USER=chris
46-
- MYSQL_PASSWORD=Chris1234
42+
- POSTGRES_DB=chris_store_dev
43+
- POSTGRES_USER=chris
44+
- POSTGRES_PASSWORD=Chris1234
4745
labels:
48-
name: "ChRIS_store MySQL Database"
46+
name: "ChRIS_store PostgreSQL Database"
4947
role: "Development database"
5048

5149
swift_service_dev:

docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
if [[ "$DJANGO_DB_MIGRATE" == 'on' ]]; then
44
if [[ "$DJANGO_SETTINGS_MODULE" == 'config.settings.local' ]]; then
5-
python migratedb.py -u root -p rootp --host chris_store_dev_db --noinput
5+
python migratedb.py -u chris -p Chris1234 -d chris_store_dev --host chris_store_dev_db --noinput
66
elif [[ "$DJANGO_SETTINGS_MODULE" == 'config.settings.production' ]]; then
7-
python migratedb.py -u root -p $MYSQL_ROOT_PASSWORD --host $DATABASE_HOST --noinput
7+
python migratedb.py -u $POSTGRES_USER -p $POSTGRES_PASSWORD -d $POSTGRES_DB --host $DATABASE_HOST --noinput
88
fi
99
fi
1010

make.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ if [[ "$1" == 'up' ]]; then
4242

4343
title -d 1 "Pulling core containers where needed..."
4444
printf "${LightCyan}%40s${Green}%-40s${Yellow}\n" \
45-
"docker pull" " mysql:8" | ./boxes.sh
46-
docker pull mysql:8 | ./boxes.sh
45+
"docker pull" " postgres:13" | ./boxes.sh
46+
docker pull postgres:13 | ./boxes.sh
4747
echo "" | ./boxes.sh
4848
printf "${LightCyan}%40s${Green}%-40s${Yellow}\n" \
4949
"docker pull " "fnndsc/docker-swift-onlyone" | ./boxes.sh
@@ -64,14 +64,14 @@ if [[ "$1" == 'up' ]]; then
6464
windowBottom
6565

6666
title -d 1 "Waiting until ChRIS store database server is ready to accept connections..."
67-
docker-compose -f docker-compose_dev.yml exec chris_store_dev_db sh -c 'while ! mysqladmin -uroot -prootp status 2> /dev/null; do sleep 5; done;' >& dc.out > /dev/null
67+
echo "This might take a few seconds..." | ./boxes.sh ${Yellow}
68+
windowBottom
69+
docker-compose -f docker-compose_dev.yml exec chris_store_dev_db sh -c 'while ! psql -U chris -d chris_store_dev -c "select 1" 2> /dev/null; do sleep 5; done;' >& dc.out > /dev/null
6870
echo -en "\033[2A\033[2K"
69-
sed -E 's/[[:alnum:]]+:/\n&/g' dc.out | ./boxes.sh
70-
# Give all permissions to chris user on the test DB. This is required for the Django tests:
71-
echo "Granting <chris> user all DB permissions...." | ./boxes.sh ${LightCyan}
72-
echo "This is required for the Django tests." | ./boxes.sh ${LightCyan}
73-
docker-compose -f docker-compose_dev.yml exec chris_store_dev_db mysql -uroot -prootp -e 'GRANT ALL PRIVILEGES ON test_chris_store_dev.* TO "chris"@"%"' >& dc.out > /dev/null
74-
cat dc.out | ./boxes.sh
71+
cat dc.out | ./boxes.sh ${LightGreen}
72+
echo "" | ./boxes.sh
73+
echo "ChRIS store database is ready to accept connections" | ./boxes.sh ${LightGreen}
74+
echo "" | ./boxes.sh
7575
windowBottom
7676

7777
title -d 1 "Running Django Unit tests..."

requirements/base.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Django==2.2.24
22
django-filter==2.4.0
33
djangorestframework==3.12.4
44
django-cors-middleware==1.5.0
5-
mysqlclient==2.0.3
6-
mysql-connector-python==8.0.25
5+
psycopg2==2.8.6
76
python-swiftclient==3.12.0
87
django-storage-swift==1.2.19
98
mod-wsgi==4.8.0

store_backend/config/settings/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
DATABASES = {
100100
'default': {
101-
'ENGINE': 'mysql.connector.django',
101+
'ENGINE': 'django.db.backends.postgresql',
102102
}
103103
}
104104

store_backend/config/settings/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
DATABASES['default']['PASSWORD'] = 'Chris1234'
8282
DATABASES['default']['TEST'] = {'NAME': 'test_chris_store_dev'}
8383
DATABASES['default']['HOST'] = 'chris_store_dev_db'
84-
DATABASES['default']['PORT'] = '3306'
84+
DATABASES['default']['PORT'] = '5432'
8585

8686
# Mail settings
8787
# ------------------------------------------------------------------------------

store_backend/config/settings/production.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def get_secret(setting, secret_type=env):
4343
# DATABASE CONFIGURATION
4444
# ------------------------------------------------------------------------------
4545
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
46-
DATABASES['default']['NAME'] = get_secret('MYSQL_DATABASE')
47-
DATABASES['default']['USER'] = get_secret('MYSQL_USER')
48-
DATABASES['default']['PASSWORD'] = get_secret('MYSQL_PASSWORD')
46+
DATABASES['default']['NAME'] = get_secret('POSTGRES_DB')
47+
DATABASES['default']['USER'] = get_secret('POSTGRES_USER')
48+
DATABASES['default']['PASSWORD'] = get_secret('POSTGRES_PASSWORD')
4949
DATABASES['default']['HOST'] = get_secret('DATABASE_HOST')
5050
DATABASES['default']['PORT'] = get_secret('DATABASE_PORT')
5151

0 commit comments

Comments
 (0)