Skip to content

Commit

Permalink
Add docker CI
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Feb 11, 2024
1 parent d2577ed commit f6ca4dd
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/docker_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: docker CI

on:
push:
branches:
- "**"
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * MON"
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: docker
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Create volume
run: bash docker_create_volume.sh
- name: Create image
run: bash docker_create_image.sh
- name: Create container
run: bash docker_create_container.sh
- name: Create database
run: bash docker_create_database.sh
- name: Start container
run: bash docker_start.sh
- name: Run tests
run: bash docker_run_tests.sh
- name: Stop container
run: bash docker_stop.sh
- name: Destroy container
run: bash docker_destroy_container.sh

warn:
runs-on: ubuntu-latest
if: github.repository == 'dmf-unicatt/turing-dmf' && github.ref == 'refs/heads/main' && github.event_name == 'schedule'
steps:
- name: Warn if scheduled workflow is about to be disabled
uses: fem-on-colab/warn-workflow-about-to-be-disabled-action@main
with:
workflow-filename: docker_ci.yml
days-elapsed: 50
6 changes: 2 additions & 4 deletions docker/docker_create_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

set -e

docker build --pull -t turing-dmf:latest -f Dockerfile ..

VOLUME_ID_FILE=".docker_volume_id"
if [[ ! -f "${VOLUME_ID_FILE}" ]]; then
echo "The database volume does not exist!"
Expand All @@ -27,10 +25,10 @@ if [[ -f "${CONTAINER_ID_FILE}" ]]; then
else
# Ensure that docker's network has been customized, otherwise the docker IP address conflicts
# with internal IPs on DMF network.
docker network create --subnet=10.200.1.0/24 turing-docker-network
docker network create --subnet=10.200.1.0/24 turing-dmf-network
# Start docker container on a fixed IP address. The corresponding mac address is generated following
# https://maclookup.app/faq/how-do-i-identify-the-mac-address-of-a-docker-container-interface
CONTAINER_ID=$(docker create --net turing-docker-network --ip 10.200.1.23 --mac-address 02:42:0a:c8:01:17 -p 8080:8080 -v /tmp/shared-turing-dmf:/tmp/shared-turing-dmf -v ${VOLUME_ID}:/mnt/database turing-dmf:latest)
CONTAINER_ID=$(docker create --net turing-dmf-network --ip 10.200.1.23 --mac-address 02:42:0a:c8:01:17 -p 8080:8080 -v /tmp/shared-turing-dmf:/tmp/shared-turing-dmf -v ${VOLUME_ID}:/mnt/database turing-dmf:latest)
echo ${CONTAINER_ID} > ${CONTAINER_ID_FILE}
echo "You can now start the web server with run docker_start.sh and visit http://localhost:8080"
echo "If the volume ${VOLUME_ID} does not contain a database, make sure to create it with docker_create_database.sh"
Expand Down
13 changes: 13 additions & 0 deletions docker/docker_create_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# Copyright (C) 2024 by the Turing @ DMF authors
#
# This file is part of Turing @ DMF.
#
# SPDX-License-Identifier: AGPL-3.0-or-later

set -e

# Do not run any further if we are not connected to the internet
wget -q --spider https://www.google.com

docker build --pull -t turing-dmf:latest -f Dockerfile ..
2 changes: 1 addition & 1 deletion docker/docker_destroy_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$( docker container inspect -f '{{.State.Running}}' ${CONTAINER_ID} )" ==
echo "Please stop it first with docker_stop.sh"
exit 1
else
docker network rm turing-docker-network
docker network rm turing-dmf-network
docker rm ${CONTAINER_ID}
rm ${CONTAINER_ID_FILE}
fi

0 comments on commit f6ca4dd

Please sign in to comment.