Add docker

This commit is contained in:
2022-02-14 20:03:53 +01:00
parent 80eb11b0c9
commit e69073ecad
32 changed files with 508 additions and 10 deletions

7
services/db/README.md Normal file
View File

@@ -0,0 +1,7 @@
# ServerCtl Database
## Setup
```bash
tern migrate
```

View File

@@ -0,0 +1,10 @@
create table sctl_user
(
id int GENERATED BY DEFAULT AS IDENTITY primary key,
email varchar(320) not null,
password_hash varchar(256) not null
);
---- create above / drop below ----
drop table sctl_user;

View File

@@ -0,0 +1,10 @@
-- Write your migrate up statements here
create unique index user_email_unique_index
on sctl_user(email);
---- create above / drop below ----
drop index user_email_unique_index;
-- Write your migrate down statements here. If this migration is irreversible
-- Then delete the separator line above.

View File

@@ -0,0 +1,14 @@
-- Write your migrate up statements here
create table sctl_project
(
id int GENERATED BY DEFAULT AS IDENTITY primary key,
data jsonb NOT NULL
);
---- create above / drop below ----
drop table sctl_project;
-- Write your migrate down statements here. If this migration is irreversible
-- Then delete the separator line above.

View File

@@ -0,0 +1,9 @@
FROM golang:1.17-bullseye
RUN go install github.com/jackc/tern@latest
COPY . /app/migration/
WORKDIR /app/migration
CMD ./wait-for-database.sh

View File

@@ -0,0 +1,34 @@
[database]
# host is required (network host or path to Unix domain socket)
host = localhost
port = 5432
# database is required
database = serverctl
# user defaults to OS user
user = serverctl
password = serverctlsecret
version_table = public.schema_version
#
# sslmode generally matches the behavior described in:
# http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION
#
# There are only two modes that most users should use:
# prefer - on trusted networks where security is not required
# verify-full - require SSL connection
sslmode = prefer
#
# sslrootcert is generally used with sslmode=verify-full
# sslrootcert = /path/to/root/ca
# Proxy the above database connection via SSH
# [ssh-tunnel]
# host =
# port = 22
# user defaults to OS user
# user =
# password is not required if using SSH agent authentication
# password =
[data]
# Any fields in the data section are available in migration templates
prefix = serverctl

View File

@@ -0,0 +1,34 @@
[database]
# host is required (network host or path to Unix domain socket)
host = db
port = 5432
# database is required
database = serverctl
# user defaults to OS user
user = serverctl
password = serverctlsecret
version_table = public.schema_version
#
# sslmode generally matches the behavior described in:
# http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION
#
# There are only two modes that most users should use:
# prefer - on trusted networks where security is not required
# verify-full - require SSL connection
sslmode = prefer
#
# sslrootcert is generally used with sslmode=verify-full
# sslrootcert = /path/to/root/ca
# Proxy the above database connection via SSH
# [ssh-tunnel]
# host =
# port = 22
# user defaults to OS user
# user =
# password is not required if using SSH agent authentication
# password =
[data]
# Any fields in the data section are available in migration templates
prefix = serverctl

View File

@@ -0,0 +1,13 @@
#!/bin/sh
# wait-for-postgres.sh
set -e
until tern status -c tern.docker.conf; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
tern migrate -c tern.docker.conf