Skip to content

Commit 019c501

Browse files
authored
Merge pull request #1795 from hashtopolis/dba-migrations-and-postgres
DBA migrations and postgres
2 parents 5eafe60 + 9f90283 commit 019c501

26 files changed

+1795
-241
lines changed

.devcontainer/docker-compose.yml renamed to .devcontainer/docker-compose.mysql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
- CONTAINER_USER_CMD_PRE
1010
- CONTAINER_USER_CMD_POST
1111
environment:
12+
HASHTOPOLIS_DB_TYPE: mysql
1213
HASHTOPOLIS_DB_USER: hashtopolis
1314
HASHTOPOLIS_DB_PASS: hashtopolis
1415
HASHTOPOLIS_DB_HOST: hashtopolis-db-dev
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
version: "3.7"
2+
services:
3+
hashtopolis-server-dev:
4+
container_name: hashtopolis-server-dev
5+
build:
6+
context: ..
7+
target: hashtopolis-server-dev
8+
args:
9+
- CONTAINER_USER_CMD_PRE
10+
- CONTAINER_USER_CMD_POST
11+
environment:
12+
HASHTOPOLIS_DB_TYPE: postgres
13+
HASHTOPOLIS_DB_USER: hashtopolis
14+
HASHTOPOLIS_DB_PASS: hashtopolis
15+
HASHTOPOLIS_DB_HOST: hashtopolis-db-dev
16+
HASHTOPOLIS_DB_DATABASE: hashtopolis
17+
HASHTOPOLIS_APIV2_ENABLE: 1
18+
depends_on:
19+
- hashtopolis-db-dev
20+
ports:
21+
- "8080:80"
22+
volumes:
23+
# This is where VS Code should expect to find your project's source code
24+
# and the value of "workspaceFolder" in .devcontainer/devcontainer.json
25+
- ..:/var/www/html
26+
- hashtopolis-server-dev:/usr/local/share/hashtopolis:Z
27+
networks:
28+
- hashtopolis_dev
29+
hashtopolis-db-dev:
30+
container_name: hashtopolis-db-dev
31+
image: postgres:13
32+
restart: always
33+
ports:
34+
- "5432:5432"
35+
volumes:
36+
- hashtopolis-db-dev:/var/lib/postgresql/data
37+
environment:
38+
POSTGRES_DB: hashtopolis
39+
POSTGRES_USER: hashtopolis
40+
POSTGRES_PASSWORD: hashtopolis
41+
networks:
42+
- hashtopolis_dev
43+
44+
volumes:
45+
hashtopolis-db-dev:
46+
hashtopolis-server-dev:
47+
48+
networks:
49+
hashtopolis_dev:
50+
# This network will also be used by the python-agent
51+
name: hashtopolis_dev
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
name: Start Hashtopolis server
22
description: Starts application containers and waits for Hashtopolis to be ready.
33

4+
inputs:
5+
db_system:
6+
description: "Used to set which DB system should be used"
7+
required: true
8+
default: "mysql"
9+
options:
10+
- "mysql"
11+
- "postgres"
12+
413
runs:
514
using: "composite"
615
steps:
716
- name: Start application containers
8-
working-directory: .devcontainer
9-
run: docker compose up -d
10-
shell: bash
11-
- name: Install composer dependencies packages
12-
run: docker exec hashtopolis-server-dev composer install --working-dir=/var/www/html/
17+
working-directory: .github
18+
run: docker compose -f docker-compose.${{ inputs.db_system }}.yml up -d
1319
shell: bash
20+
# should not be needed anymore as it is installed during build
21+
# - name: Install composer dependencies packages
22+
# run: docker exec hashtopolis-server-dev composer install --working-dir=/var/www/html/
23+
# shell: bash
1424
- name: Wait until entrypoint is finished and Hashtopolis is started
1525
run: bash .github/scripts/await-hashtopolis-startup.sh
1626
shell: bash

.github/docker-compose.mysql.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: "3.7"
2+
services:
3+
hashtopolis-server-dev:
4+
container_name: hashtopolis-server-dev
5+
build:
6+
context: ..
7+
target: hashtopolis-server-dev
8+
args:
9+
- CONTAINER_USER_CMD_PRE
10+
- CONTAINER_USER_CMD_POST
11+
environment:
12+
HASHTOPOLIS_DB_TYPE: mysql
13+
HASHTOPOLIS_DB_USER: hashtopolis
14+
HASHTOPOLIS_DB_PASS: hashtopolis
15+
HASHTOPOLIS_DB_HOST: hashtopolis-db-dev
16+
HASHTOPOLIS_DB_DATABASE: hashtopolis
17+
HASHTOPOLIS_APIV2_ENABLE: 1
18+
depends_on:
19+
- hashtopolis-db-dev
20+
ports:
21+
- "8080:80"
22+
volumes:
23+
- hashtopolis-server-dev:/usr/local/share/hashtopolis:Z
24+
networks:
25+
- hashtopolis_dev
26+
hashtopolis-db-dev:
27+
container_name: hashtopolis-db-dev
28+
image: mysql:8.0
29+
restart: always
30+
ports:
31+
- "3306:3306"
32+
volumes:
33+
- hashtopolis-db-dev:/var/lib/mysql
34+
environment:
35+
MYSQL_ROOT_PASSWORD: hashtopolis
36+
MYSQL_DATABASE: hashtopolis
37+
MYSQL_USER: hashtopolis
38+
MYSQL_PASSWORD: hashtopolis
39+
networks:
40+
- hashtopolis_dev
41+
volumes:
42+
hashtopolis-db-dev:
43+
hashtopolis-server-dev:
44+
45+
networks:
46+
hashtopolis_dev:
47+
name: hashtopolis_dev
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: "3.7"
2+
services:
3+
hashtopolis-server-dev:
4+
container_name: hashtopolis-server-dev
5+
build:
6+
context: ..
7+
target: hashtopolis-server-dev
8+
args:
9+
- CONTAINER_USER_CMD_PRE
10+
- CONTAINER_USER_CMD_POST
11+
environment:
12+
HASHTOPOLIS_DB_TYPE: postgres
13+
HASHTOPOLIS_DB_USER: hashtopolis
14+
HASHTOPOLIS_DB_PASS: hashtopolis
15+
HASHTOPOLIS_DB_HOST: hashtopolis-db-dev
16+
HASHTOPOLIS_DB_DATABASE: hashtopolis
17+
HASHTOPOLIS_APIV2_ENABLE: 1
18+
depends_on:
19+
- hashtopolis-db-dev
20+
ports:
21+
- "8080:80"
22+
volumes:
23+
- hashtopolis-server-dev:/usr/local/share/hashtopolis:Z
24+
networks:
25+
- hashtopolis_dev
26+
hashtopolis-db-dev:
27+
container_name: hashtopolis-db-dev
28+
image: postgres:13
29+
restart: always
30+
ports:
31+
- "5432:5432"
32+
volumes:
33+
- hashtopolis-db-dev:/var/lib/postgresql/data
34+
environment:
35+
POSTGRES_DB: hashtopolis
36+
POSTGRES_USER: hashtopolis
37+
POSTGRES_PASSWORD: hashtopolis
38+
networks:
39+
- hashtopolis_dev
40+
41+
volumes:
42+
hashtopolis-db-dev:
43+
hashtopolis-server-dev:
44+
45+
networks:
46+
hashtopolis_dev:
47+
name: hashtopolis_dev

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ on:
1313
jobs:
1414
build:
1515
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
include:
19+
- db_system: mysql
20+
- db_system: postgres
1621
steps:
1722
- name: Checkout repository
1823
uses: actions/checkout@v3
1924
- name: Start Hashtopolis server
2025
uses: ./.github/actions/start-hashtopolis
26+
with:
27+
db_system: ${{ matrix.db_system }}
2128
- name: Give Apache permissions on necessary directories # for the tests, only src/files and src/inc/utils/locks seem necessary
2229
run: docker exec -u root hashtopolis-server-dev bash -c "chown -R www-data:www-data /var/www/html/src && chmod -R g+w /var/www/html/src"
23-
- name: Run test suite
24-
run: docker exec hashtopolis-server-dev php /var/www/html/ci/run.php -vmaster
2530
- name: Test with pytest
2631
run: docker exec hashtopolis-server-dev pytest /var/www/html/ci/apiv2
2732
- name: Test if pytest is removing all test objects

.github/workflows/docs-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
sudo apt-get install npm
3030
- name: Start Hashtopolis server
3131
uses: ./.github/actions/start-hashtopolis
32+
with:
33+
db_system: "mysql"
3234
- name: Download newest apiv2 spec
3335
run: |
3436
wget http://localhost:8080/api/v2/openapi.json -P /tmp/

.github/workflows/docs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ jobs:
2626
sudo apt-get install php
2727
sudo apt-get install -y lftp
2828
sudo apt-get install nodejs
29-
sudo apt-get install npm
29+
sudo apt-get install npm
3030
- name: Start Hashtopolis server
3131
uses: ./.github/actions/start-hashtopolis
32+
with:
33+
db_system: "mysql"
3234
- name: Download newest apiv2 spec
3335
run: |
3436
wget http://localhost:8080/api/v2/openapi.json -P /tmp/

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
FROM rust:1.91-trixie AS prebuild
2+
3+
RUN cargo install sqlx-cli --no-default-features --features native-tls,mysql,postgres
4+
15
FROM alpine/git AS preprocess
26

37
COPY .gi[t] /.git
@@ -37,12 +41,12 @@ RUN apt-get update \
3741
#
3842
# Install git, procps, lsb-release (useful for CLI installs)
3943
&& apt-get -y install git iproute2 procps lsb-release \
40-
&& apt-get -y install mariadb-client \
44+
&& apt-get -y install mariadb-client postgresql-client libpq-dev \
4145
&& apt-get -y install libpng-dev \
4246
&& apt-get -y install ssmtp \
4347
\
4448
# Install extensions (optional)
45-
&& docker-php-ext-install pdo_mysql gd \
49+
&& docker-php-ext-install pdo_mysql pgsql pdo_pgsql gd \
4650
\
4751
# Install Composer
4852
&& curl -sS https://getcomposer.org/installer | php \
@@ -82,6 +86,8 @@ RUN mkdir -p ${HASHTOPOLIS_DOCUMENT_ROOT} \
8286
&& chown www-data:www-data ${HASHTOPOLIS_BINARIES_PATH} \
8387
&& chmod g+w ${HASHTOPOLIS_BINARIES_PATH}
8488

89+
COPY --from=prebuild /usr/local/cargo/bin/sqlx /usr/bin/
90+
8591
COPY --from=preprocess /HEA[D] ${HASHTOPOLIS_DOCUMENT_ROOT}/../.git/
8692

8793
# Install composer

ci/HashtopolisTest.class.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class HashtopolisTest {
1919
protected $user;
2020
protected $apiKey;
2121

22-
const USER_PASS = "HG78Ghdfs87gh";
22+
const USER_PASS = "hashtopolis";
2323

2424
const RUN_FULL = 0;
2525
const RUN_FAST = 1;
@@ -70,28 +70,27 @@ public function init($version) {
7070
global $PEPPER, $VERSION;
7171

7272
// drop old data and create empty DB
73-
Factory::getAgentFactory()->getDB()->query("DROP DATABASE IF EXISTS hashtopolis");
73+
/*Factory::getAgentFactory()->getDB()->query("DROP DATABASE IF EXISTS hashtopolis");
7474
Factory::getAgentFactory()->getDB()->query("CREATE DATABASE hashtopolis");
7575
Factory::getAgentFactory()->getDB()->query("USE hashtopolis");
7676
7777
// load DB
7878
if ($version == "master") {
79-
Factory::getAgentFactory()->getDB()->query(file_get_contents(dirname(__FILE__) ."/../src/install/hashtopolis.sql"));
79+
Factory::getAgentFactory()->getDB()->query(file_get_contents(dirname(__FILE__) ."/../src/migrations/mysql/20251127000000_initial.sql"));
8080
}
8181
else {
8282
Factory::getAgentFactory()->getDB()->query(file_get_contents(dirname(__FILE__) . "/files/db_" . $version . ".sql"));
8383
}
8484
85-
sleep(1);
85+
sleep(1);*/
8686

8787
// insert user and api key
88-
$salt = Util::randomString(30);
88+
/*$salt = Util::randomString(30);
8989
$hash = Encryption::passwordHash(HashtopolisTest::USER_PASS, $salt);
9090
$this->user = new User(null, 'testuser', '', $hash, $salt, 1, 0, 0, 0, 3600, AccessUtils::getOrCreateDefaultAccessGroup()->getId(), 0, '', '', '', '');
91-
$this->user = Factory::getUserFactory()->save($this->user);
92-
$accessGroup = new AccessGroupUser(null, 1, $this->user->getId());
93-
Factory::getAccessGroupUserFactory()->save($accessGroup);
94-
$this->apiKey = new ApiKey(null, 0, time() + 3600, 'mykey', 0, $this->user->getId(), 1);
91+
$this->user = Factory::getUserFactory()->save($this->user);*/
92+
AccessUtils::getOrCreateDefaultAccessGroup();
93+
$this->apiKey = new ApiKey(null, 0, time() + 3600, 'mykey', 0, 1, 1);
9594
$this->apiKey = Factory::getApiKeyFactory()->save($this->apiKey);
9695
// $versionStore = new StoredValue("version", ($version == 'master') ? explode("+", $VERSION)[0] : $version);
9796
// Factory::getStoredValueFactory()->save($versionStore);

0 commit comments

Comments
 (0)