Verified Commit ee52769b authored by Joakim Saario's avatar Joakim Saario
Browse files

WIP: Docker setup

parent 1874e821
Pipeline #8150 passed with stage
in 2 minutes and 19 seconds
/aurweb.sqlite3
FROM archlinux
COPY . /aurweb
WORKDIR /aurweb
# Install dependencies. Note that they are split up in multiple layers to speed
# up the build process when rebuilding the image. Dependencies are grouped
# together by compontent and those that are more unlikely to change are
# installed in earlier layers.
# Install NGINX
RUN pacman -Syu --noconfirm nginx
# Install database
RUN pacman -Syu --noconfirm mariadb mariadb-clients
# Install PHP dependencies
RUN pacman -Syu --noconfirm php
# Install dependencies.
RUN pacman -Syu --noconfirm base-devel git gpgme protobuf pyalpm \
python-mysql-connector python-pygit2 python-srcinfo python-bleach \
python-markdown python-sqlalchemy python-alembic python-pytest \
python-werkzeug python-pytest-tap python-fastapi nginx python-authlib \
python-itsdangerous python-httpx python-jinja python-pytest-cov \
python-requests python-aiofiles python-python-multipart \
python-pytest-asyncio python-coverage hypercorn python-bcrypt \
python-email-validator openssh python-lxml
python-mysqlclient python-pygit2 python-srcinfo python-bleach python-markdown \
python-sqlalchemy python-alembic python-pytest python-werkzeug \
python-pytest-tap python-fastapi nginx python-authlib python-itsdangerous \
python-httpx python-jinja python-pytest-cov python-requests python-aiofiles \
python-python-multipart python-pytest-asyncio python-coverage hypercorn \
python-bcrypt python-email-validator openssh python-lxml
# Remove aurweb.sqlite3 if it was copied over via COPY.
RUN rm -fv aurweb.sqlite3
# Copy various docker-related configs and scripts
COPY docker /
# Setup our test config.
RUN sed -r "s;YOUR_AUR_ROOT;/aurweb;g" conf/config.dev > conf/config
# Install translations.
RUN AUR_CONFIG=conf/config make -C po all install
WORKDIR /aurweb
COPY . .
# Initialize the database.
RUN AUR_CONFIG=conf/config python -m aurweb.initdb
ENV AUR_CONFIG conf/config
# Test everything!
RUN make -C test
# Setup our test config.
RUN sed -r 's;YOUR_AUR_ROOT;/aurweb;g' conf/config.dev | \
sed -r '/sqlite/d' | \
sed -r 's/^;?(backend).*/\1 = mysql/' | \
sed -r 's/^;?(host).*/\1 = mysql/' | \
sed -r 's/^;?(name).*/\1 = aurweb/' | \
sed -r 's/^;?(user).*/\1 = aur/' | \
sed -r 's/^;?(password).*/\1 = aur/' > "${AUR_CONFIG}"
# Produce a coverage report.
RUN coverage report --include='aurweb/*'
# Install translations.
RUN make -C po all install
AUR_WEB := conf/config
.PHONY: test
test:
python -m aurweb.initdb
# Test everything!
make -C test
# Produce a coverage report.
coverage report --include='aurweb/*'
# Docker wrappers
define docker
docker-compose run \
--rm \
--entrypoint $(1) \
aurweb-fastapi \
$(2)
endef
define docker-make
$(call docker,make,$(1))
endef
.PHONY: docker-test
docker-test:
$(call docker-make,test)
version: "3.8"
services:
aurweb-fastapi:
build: .
image: aurweb:latest
init: true
command: python -u -m hypercorn -b 0.0.0.0:8082 aurweb.asgi:app
volumes:
- ./aurweb:/aurweb/aurweb
- ./migrations:/aurweb/migrations
- ./alembic.ini:/aurweb/alembic.ini
- ./schema:/aurweb/schema
- ./test:/aurweb/test
- ./templates:/aurweb/templates
- ./Makefile:/aurweb/Makefile
ports:
- 8082:8082
aurweb-php:
image: aurweb:latest
init: true
command: php -S 0.0.0.0:8081 -t /aurweb/web/html
volumes:
- ./web:/aurweb/web
ports:
- 8081:8081
nginx:
image: aurweb:latest
init: true
command: nginx
volumes:
- ./docker/etc/nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- 8080:8080
mysql:
image: aurweb:latest
init: true
working_dir: /var/lib/mysql
entrypoint: /mysql-entrypoint.sh
command: mysqld_safe --datadir=/var/lib/mysql
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
volumes:
mysql_data: {}
events {}
daemon off;
error_log /dev/stderr info;
pid /run/nginx.pid;
http {
access_log /dev/stdout;
server {
listen 8080;
location / {
proxy_pass http://aurweb-php:8081;
}
location /sso {
proxy_pass http://aurweb-fastapi:8082;
}
}
}
#!/bin/bash
set -euo pipefail
init_datadir() {
mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
mysqld_safe --datadir=/var/lib/mysql &
until : > /dev/tcp/127.0.0.1/3306; do
sleep 1s
done
mysql -u root <<' EOSQL'
CREATE USER 'aur'@'%' IDENTIFIED BY 'aur';
CREATE DATABASE aurweb;
GRANT ALL PRIVILEGES ON aurweb.* TO 'aur'@'%';
FLUSH PRIVILEGES;
EOSQL
mysqladmin -uroot shutdown
}
# Only initialize the datadir if it's uninitialized.
if ! test -d /var/lib/mysql/mysql; then
init_datadir
fi
exec "$@"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment