Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions dockerfiles/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-include setenv.sh

.PHONY: all create-env build

create-env: ## Force write/overwrite the .env file
@echo "BASE_IMAGE=${BASE_IMAGE}\n" \
"PG_VERSION=$(PG_VERSION)\n" \
"INSTALL_REPO=$(INSTALL_REPO)\n" \
"CONFIG_DIR=${CONFIG_DIR}\n" \
"DOCKER_BIN=${DOCKER_BIN}\n" \
"SERVER_PORT=${SERVER_PORT}\n" \
"PG_NAME=$(PG_NAME)\n" \
"DACHS_NAME=$(DACHS_NAME)\n" \
"GAVO_DATA=$(GAVO_DATA)"> .env

build: create-env ## Build the Docker images using central environment variables
@echo "Building images with PG_VERSION=$(PG_VERSION)..."
docker compose build --no-cache=true \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg PG_VERSION=$(PG_VERSION) \
--build-arg INSTALL_REPO=$(INSTALL_REPO) \
--build-arg CONFIG_DIR=$(CONFIG_DIR) \
--build-arg DOCKER_BIN=$(DOCKER_BIN) \
--build-arg GAVO_DATA=$(GAVO_DATA)

up: create-env ## Start the containers in the background
docker compose up -d

down: create-env ## Stop and remove containers
docker compose down

update_config: ## Update gavo.rc and metadata (uses CONFIG_DIR)
@echo "Updating DaCHS configuration in container from $(CONFIG_DIR)..."
docker cp "${CONFIG_DIR}/gavo.rc" "${DACHS_NAME}:/etc/gavo.rc"
##docker cp "${CONFIG_DIR}/defaultmeta.txt" "${DACHS_NAME}:/var/gavo/etc/"
##docker cp "${CONFIG_DIR}/userconfig.rd" "${DACHS_NAME}:/var/gavo/etc/"
docker exec -it ${DACHS_NAME} sh -c "dachs pub //services"

restart: ## Restart the DaCHS server
docker exec $(DACHS_NAME) dachs serve restart
64 changes: 52 additions & 12 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ In default _compose_ file (`docker-compose.yml`) there is `dachs` (and `awstats`
In _compose_ `docker-compose.full.yml`, you'll see `dachs-server` and `dachs-postgres`
(and `awstats`) composing individual services.


## Build details
Have a look in the [README file in `dachs/`](dachs/README.md) for details on
building the individual containers.

## Building dachs in single image

## Run compose
### Run compose
> If you don't have yet, install [`docker-compose`](https://docs.docker.com/compose/install/).

To run (and build if not yet) the containers:
Expand All @@ -40,24 +39,18 @@ This will use `docker-compose.yml` to build and run containers.
The default Dachs container built is the _latest_ `dachs` container
-- using GAVO's apt repository.

To run dachs/postgres server containers individually, `docker-compose.full.yml`
is a sample of such setup:

```bash
$ docker-compose -f docker-compose.full.yml
```
To run dachs/postgres server containers individually, see description below.


## Build compose
### Build compose

To (re)build the containers defined in a compose file:

```bash
$ docker-compose build
```


## Environment variables
### Environment variables
The variables used in the _compose_ files can be defined in an "env" file
to fix some settings on the containers building and running.

Expand All @@ -78,3 +71,50 @@ Example run:
```bash
$ docker-compose --env-file env.rc up
```

## Composed setup with separate server and database

### Container Specifications

The VO server is split into two functional components:

1. Database Container (Dockerfile.dachs_postgres)
2. Application Container (Dockerfile.dachs_server): Mounts `gavo.rc` to `/etc/gavo.rc` and expects the database to be reachable on startup

Use the docker-compose.full.yml (renamed to docker-compose.yml), variable setting in setenv.sh and make commands in the root directory to build the images.

As the images use the Debian package system for installation, make sure that the according postgres version is available through apt.

### Building the containers

To build the containers,

#### 1. Set the relevant environment variables in `setenv.sh` and run

```bash
source setenv.sh
```

In this file, the container names, endpoint for the dachs server and paths to supplementary files are defined. The files at `/bin_composed` are obligatory for running the containers, additional settings can be added by specifying a $CONFIGS folder holding e.g. files like the defaultmeta.txt.

#### 2. Building the containers

The included `Makefile` provides a standardized interface for building and running the stack.

* **Build the images**:
```bash
make build
```
*This executes `docker compose build` using the variables defined in your environment.*

* **Start the services**:
```bash
make up
```
*Starts the PostgreSQL and DaCHS containers in the background.*

* **Stop the services**:
```bash
make down
```

122 changes: 52 additions & 70 deletions dockerfiles/dachs/Dockerfile.dachs_postgres
Original file line number Diff line number Diff line change
@@ -1,95 +1,77 @@
# 1. Declare ARGs (Values come from --build-arg or docker-compose)
ARG BASE_IMAGE="debian:stable"

# BUILD argument for extra repositories (besides debian/stable) to install dachs.
# Options are:
# - "gavo/beta" (gavo/release + gavo/beta)
# - "backports" (debian/backports)
# - "main" (debian/main)
# * Default is "main"
ARG PG_VERSION="17"
ARG INSTALL_REPO="main"

# PostgreSQL version to install
# * Default is "15"
ARG PG_VERSION="15"
ARG DOCKER_BIN="bin"

FROM $BASE_IMAGE

LABEL Description=DaCHS\ is\ a\ publishing\ infrastructure\ for\ the\ Virtual\ Observatory. \
# Re-declare for use in RUN commands
ARG PG_VERSION
ARG INSTALL_REPO
ARG DOCKER_BIN

LABEL Description=DaCHS\ Postgres\ for\ compose.\ DaCHS\ is\ a\ publishing\ infrastructure\ for\ the\ Virtual\ Observatory. \
Reference=http://arxiv.org/abs/1408.5733

# Everyday tools
# 1. Install System Tools
RUN DEBIAN_FRONTEND='noninteractive' \
&& apt-get update \
&& apt-get install -y \
curl \
git \
gnupg2 \
locales \
procps \
sudo \
vim \
wget \
curl git gnupg2 locales procps sudo vim wget \
&& apt-get clean


# 2. Setup GAVO Repository
ENV _APT_SOURCES="/etc/apt/sources.list.d/gavo.list"
COPY etc/apt_sources.list "$_APT_SOURCES"
COPY ${DOCKER_BIN}/apt_sources.list "$_APT_SOURCES"

# Some fixes on the environment
# ---
# This is the brute-force solution for Debian;
# I am having problems in set locales non-interactively,
# and since I really need the "C/UTF8" for postgres, will just set it for all.
ENV LC_ALL=C.UTF-8
RUN echo LC_ALL="$LC_ALL" > /etc/default/locale

RUN sed -i 's/exit 101/exit 0/' /usr/sbin/policy-rc.d
# ---

# Setup GAVO key, then repositories according to INSTALL_REPO
# RUN wget -qO - http://docs.g-vo.org/archive-key.asc | apt-key add -
RUN curl https://vo.ari.uni-heidelberg.de/debian/gavo-archive-keyring.asc \
RUN curl -s https://vo.ari.uni-heidelberg.de/debian/gavo-archive-keyring.asc \
| tee /etc/apt/trusted.gpg.d/gavo-archive.keyring.asc

# If installing any version other than "main", backports is in there:
RUN [ "$INSTALL_REPO" != "main" ] \
&& sed -i '/deb.*backports/s/^#//' $_APT_SOURCES \
|| echo "NOT using debian/backports repo"
|| echo "Using main repo only"

# If installing -- i.e, "beta" version -- uncomment gavo's release and beta repos
RUN [ "$INSTALL_REPO" = "gavo/beta" -o "$INSTALL_REPO" = "latest" -o "$INSTALL_REPO" = "gavo" ] \
&& sed -i '/deb.*heidelberg/s/^#//' $_APT_SOURCES \
|| echo "NOT using gavo beta/release repos"

RUN echo "Using the following repositories:" && grep "deb" $_APT_SOURCES
# 3. Environment Fixes
ENV LC_ALL=C.UTF-8
RUN echo LC_ALL="$LC_ALL" > /etc/default/locale
RUN sed -i 's/exit 101/exit 0/' /usr/sbin/policy-rc.d

# 4. Install Postgres and VO Extensions
ENV PG_VERSION=${PG_VERSION}
RUN DEBIAN_FRONTEND='noninteractive' \
&& apt-get update \
&& apt-get install -y \
postgresql-$PG_VERSION \
postgresql-$PG_VERSION-pgsphere \
postgresql-$PG_VERSION-q3c \
&& apt-get clean

RUN DEBIAN_FRONTEND='noninteractive' && \
apt-get update && \
apt-get install -y postgresql-$PG_VERSION && \
apt-get install -y postgresql-$PG_VERSION-pgsphere && \
apt-get install -y postgresql-$PG_VERSION-q3c && \
apt-get clean

RUN PGFILE=/etc/postgresql/${PG_VERSION}/main/pg_hba.conf && \
echo 'host all all 172.17.0.0/24 trust' >> $PGFILE && \
echo "listen_addresses='*'" >> "${PGFILE%/*}/postgresql.conf"

RUN PGDATA=/var/lib/postgresql/${PG_VERSION} \
mkdir -p -m 777 /var/run/postgresql/${PG_VERSION}-main.pg_stat_tmp/ && \
su - postgres -c "/usr/lib/postgresql/${PG_VERSION}/bin/postgres \
-c config_file=/etc/postgresql/${PG_VERSION}/main/postgresql.conf \
-c logging_collector=on" & \
sleep 5 && \
su postgres -c "createuser -s dachsroot" && \
su postgres -c "createuser -s root" && \
su postgres -c "createdb gavo"
# 5. Network Configuration (Allow Swarm Overlay Network)
RUN PGFILE=/etc/postgresql/${PG_VERSION}/main/pg_hba.conf \
&& echo 'host all all 0.0.0.0/0 trust' >> $PGFILE \
&& echo "listen_addresses='*'" >> "${PGFILE%/*}/postgresql.conf"

# 6. Database Initialization with Robust Wait Loop
RUN mkdir -p -m 777 /var/run/postgresql/${PG_VERSION}-main.pg_stat_tmp/ && \
chown postgres:postgres /var/run/postgresql/${PG_VERSION}-main.pg_stat_tmp/ && \
# Start Postgres in background
su - postgres -c "/usr/lib/postgresql/${PG_VERSION}/bin/postgres \
-D /var/lib/postgresql/${PG_VERSION}/main \
-c config_file=/etc/postgresql/${PG_VERSION}/main/postgresql.conf" & \
# THE ALTERNATIVE TO SLEEP: Wait until pg_isready returns 0 (ready)
until su postgres -c "pg_isready"; do \
echo "Waiting for Postgres to start..."; \
sleep 1; \
done && \
# Run setup commands
su postgres -c "createuser -s dachsroot" && \
su postgres -c "createuser -s root" && \
su postgres -c "createdb gavo" && \
# Shutdown gracefully to finalize the layer
su postgres -c "/usr/lib/postgresql/${PG_VERSION}/bin/pg_ctl -D /var/lib/postgresql/${PG_VERSION}/main stop"

# Expose Postgres port
EXPOSE 5432

COPY bin/dachs_postgres.sh /serve.sh

COPY ${DOCKER_BIN}/dachs_postgres.sh /serve.sh
ENTRYPOINT ["/bin/bash"]
CMD ["--rcfile", "/serve.sh"]
CMD ["--rcfile", "/serve.sh"]
Loading
Loading