Skip to content

Commit

Permalink
Updates api container to support running tests (#21)
Browse files Browse the repository at this point in the history
This change replaces testing with the single monolithic container.
  • Loading branch information
dgarciabriseno authored Dec 18, 2023
1 parent d8317ec commit 53190a3
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 33 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Build check

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

Expand All @@ -14,8 +12,24 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- uses: isbang/compose-action@v1.5.1
with:
compose-file: "./compose.yaml"
up-flags: "--build"
down-flags: "--volumes"

- name: Build containers
run: docker compose build

- name: Get latest api version
run: cd api && git checkout origin/main

- name: Get latest helioviewer.org version
run: cd helioviewer.org && git checkout origin/main

- name: Make writeable configuration files
run: |
touch api/install/settings/settings.cfg
chmod o+rw api/install/settings/settings.cfg
touch api/settings/Config.ini
chmod o+rw api/settings/Config.ini
touch api/settings/Config.php
chmod o+rw api/settings/Config.php
- name: Check that containers start and become healthy
run: docker compose up -d --wait
24 changes: 24 additions & 0 deletions .github/workflows/push-to-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build check

on:
push:
branches: [ "main" ]

jobs:
build-containers:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build containers
run: docker compose build

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push to hub
run: docker compose push
16 changes: 16 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- 6379:6379
restart: on-failure
api:
image: dgarciabriseno/helioviewer-api-dev
build:
dockerfile: ./compose/dockerfiles/api_server.Dockerfile
ports:
Expand All @@ -27,6 +28,12 @@ services:
- redis
restart: on-failure
platform: linux/amd64
healthcheck:
# Check every 10 seconds, wait up to 2 minutes
test: ["CMD", "ls", "/tmp/container_ready"]
interval: 10s
timeout: 1s
retries: 12
volumes:
- type: volume
source: jp2_volume
Expand All @@ -38,6 +45,7 @@ services:
target: /var/www/api.helioviewer.org
- api_logs:/var/www/api.helioviewer.org/log
web:
image: dgarciabriseno/helioviewer-web-dev
build:
dockerfile: ./compose/dockerfiles/webserver.Dockerfile
ports:
Expand All @@ -54,6 +62,7 @@ services:
target: /var/www/api.helioviewer.org
- cache:/var/www/html/cache
movies:
image: dgarciabriseno/helioviewer-movies-dev
depends_on:
- redis
build:
Expand All @@ -66,12 +75,19 @@ services:
- jp2_volume:/tmp/jp2
- cache:/var/www/helioviewer.org/cache
cli:
image: dgarciabriseno/helioviewer-cli-dev
build:
dockerfile: ./compose/dockerfiles/cli.Dockerfile
depends_on:
database:
condition: service_healthy
platform: linux/x86_64
healthcheck:
# Check every 10 seconds, wait up to 2 minutes
test: ["CMD", "ls", "/tmp/jp2/LASCO-C2/2023/12/01/white-light/"]
interval: 10s
timeout: 1s
retries: 12
volumes:
- type: volume
source: jp2_volume
Expand Down
41 changes: 20 additions & 21 deletions compose/dockerfiles/api_server.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
FROM php:8.0.27-apache
FROM php:8.0.30-apache

# Install API dependencies
# Setup kakadu for kdu_* commands
# Setup apache to serve from the docroot folder.
# Install composer for php dependencies
ENV APACHE_DOCUMENT_ROOT /var/www/api.helioviewer.org/docroot
COPY ./compose/scripts/install_composer.sh /root
COPY api/install/kakadu/Kakadu_v6_4_1-00781N_Linux-64-bit-Compiled.tar.gz kdu.tar.gz
RUN apt update \
&& apt install -y unzip libpng-dev libjpeg-dev python3 python3-venv \
&& apt install -y unzip libpng-dev libjpeg-dev libfreetype-dev python3-dev libmariadb-dev python3-venv \
&& curl -s --output imagemagick.zip -X GET https://codeload.github.com/ImageMagick/ImageMagick6/zip/refs/tags/6.9.12-70 \
&& unzip imagemagick.zip \
&& rm imagemagick.zip \
Expand All @@ -17,28 +23,21 @@ RUN apt update
&& pecl install redis \
&& pecl install xdebug \
&& pecl install imagick \
&& docker-php-ext-enable redis xdebug imagick

# Setup kakadu for kdu_* commands
COPY api/install/kakadu/Kakadu_v6_4_1-00781N_Linux-64-bit-Compiled.tar.gz /kakadu/kdu.tar.gz
WORKDIR /kakadu
RUN tar xzf kdu.tar.gz \
&& mv bin/* /usr/local/bin \
&& mv lib/* /usr/lib \
&& rm -r bin lib

# Setup apache to serve from the docroot folder.
ENV APACHE_DOCUMENT_ROOT /var/www/api.helioviewer.org/docroot
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
&& docker-php-ext-enable redis xdebug imagick \
&& curl -X GET "https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz" --output ffmpeg.tar.xz \
&& tar xf ffmpeg.tar.xz \
&& mv ffmpeg-6.1-amd64-static/ffmpeg /usr/local/bin \
&& rm -rf ffmpeg.tar.xz ffmpeg-6.1-amd64-static \
&& tar xzf kdu.tar.gz \
&& mv bin/* /usr/local/bin \
&& mv lib/* /usr/lib \
&& rm -r bin lib \
&& sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
&& sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \
&& bash /root/install_composer.sh

# Enable remote debugging with xdebug
COPY ./compose/99-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Install composer for php dependencies
COPY ./compose/scripts/install_composer.sh /root
RUN bash /root/install_composer.sh

# Copy the startup script over.
COPY ./compose/scripts/api_config.sh /root
COPY ./compose/scripts/api_startup.sh /root
Expand Down
8 changes: 8 additions & 0 deletions compose/scripts/api_startup.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#!/bin/bash
set -e
READY_FILE=/tmp/container_ready
rm -f $READY_FILE

mkdir -p /var/www/helioviewer.org/cache/tiles
chmod 777 /var/www/helioviewer.org/cache/tiles

COMPOSER_HOME=/root composer install
/var/www/api.helioviewer.org/vendor/bin/start_hgs2hpc

pushd /var/www/api.helioviewer.org/install
python3 -m venv venv
venv/bin/python -m pip install -r test_requirements.txt
popd

bash /root/api_config.sh

chmod 777 /var/www/api.helioviewer.org/log

source /etc/apache2/envvars
touch $READY_FILE
/usr/sbin/apache2 -DFOREGROUND
13 changes: 10 additions & 3 deletions compose/scripts/cli_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ cp /home/admin/2021_06_01__00_01_29_132__SDO_AIA_AIA_304.jp2 /tmp/jp2
./headless_setup.sh

SETTINGS_DIR=/home/admin/api/install/settings
sed "s|dbhost = localhost|dbhost = database|" ${SETTINGS_DIR}/settings.example.cfg > ${SETTINGS_DIR}/settings.cfg
sed -i "s|/mnt/data/jp2|/tmp/jp2|" ${SETTINGS_DIR}/settings.cfg
sed -i "s|server = localhost|server=|" ${SETTINGS_DIR}/settings.cfg
TMPFILE=/tmp/settings.cfg
sed "s|dbhost = localhost|dbhost = database|" ${SETTINGS_DIR}/settings.example.cfg > $TMPFILE
sed -i "s|/mnt/data/hvpull|/tmp|" $TMPFILE
sed -i "s|/mnt/data/jp2|/tmp/jp2|" $TMPFILE
sed "s|server = localhost|server=|" $TMPFILE > ${SETTINGS_DIR}/settings.cfg

# Download some test data
set -e
cd /home/admin/api/install
python downloader.py -d hv_soho -s "2023-12-01 00:00:00" -e "2023-12-01 01:00:00"

tail -f /dev/null
2 changes: 1 addition & 1 deletion helioviewer.org

0 comments on commit 53190a3

Please sign in to comment.