forked from UCL-INGI/INGInious
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[deploy] add docker compose deployment (UCL-INGI#882)
* Add backend service * Add agent-docker service * Add agent-mcq service * Add mongo-db container * Layered services images * Add frontend service * [deploy] From Ubuntu to Rocky8 * [deploy] Update README * [deploy] Add initial MongoDB setup * [deploy] Update INGInious stack doc * [deploy] Rebase and update documentation * [deploy] Revert setup sub-division * [deploy] Add core containers build to CI * Use code escape in documentation Suggested changes by @anthonygego Co-authored-by: Anthony Gégo <[email protected]> * [deploy/compose] Build base image in stack deploy * [deploy] Update doc about core containers build * [deploy/base] Document the containerfile * [deploy] Update review comments - Add .env file with defaults values for REGISTRY and VERSION variables - Fix "docker compose" syntax for modern deployements --------- Co-authored-by: Anthony Gégo <[email protected]>
- Loading branch information
1 parent
faf165c
commit 51f525d
Showing
13 changed files
with
330 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
REGISTRY=ghcr.io | ||
VERSION=latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Build and push core containers | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
containers_build_and_push: | ||
uses: INGInious/.github/.github/workflows/containers.yml@6506916a602fc6bf47d6e8f34586732d3c8e1502 | ||
with: | ||
working-directory: base-containers | ||
context-path: context.yml | ||
compose-path: compose.yml | ||
registry: ghcr.io | ||
container_type: core | ||
secrets: | ||
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }} | ||
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
backend: tcp://backend:2000 | ||
backup_directory: /inginious/backups | ||
local-config: {} | ||
mongo_opt: | ||
database: INGInious | ||
host: db | ||
plugins: [] | ||
session_parameters: | ||
ignore_change_ip: false | ||
secret_key: 96f4628a2e4d0ce26b6352713f8ac8359b838f4800f1972790622899664bd0f4 | ||
secure: false | ||
timeout: 86400 | ||
superadmins: | ||
- superadmin | ||
tasks_directory: /inginious/tasks | ||
use_minified_js: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ARG VERSION=latest | ||
ARG REGISTRY | ||
|
||
FROM ${REGISTRY}/inginious/core-base:${VERSION} | ||
|
||
COPY inginious/agent/__init__.py inginious/agent/ | ||
COPY inginious/agent/docker_agent/ inginious/agent/docker_agent/ | ||
COPY inginious-agent-docker . | ||
|
||
RUN dnf install -y gcc python39-devel | ||
|
||
# See https://github.com/pypa/setuptools_scm/#usage-from-docker | ||
RUN --mount=source=.git,target=.git,type=bind \ | ||
pip3 install --no-cache-dir -e . | ||
|
||
CMD ["sh", "-c", "python3 inginious-agent-docker ${BACKEND} --tmpdir=/tmp/agent_data/"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ARG VERSION=latest | ||
ARG REGISTRY | ||
|
||
FROM ${REGISTRY}/inginious/core-base:${VERSION} | ||
|
||
COPY inginious/agent/__init__.py inginious/agent/ | ||
COPY inginious/agent/mcq_agent/ inginious/agent/mcq_agent/ | ||
COPY inginious-agent-mcq . | ||
|
||
# See https://github.com/pypa/setuptools_scm/#usage-from-docker | ||
RUN --mount=source=.git,target=.git,type=bind \ | ||
pip3 install --no-cache-dir -e . | ||
|
||
CMD ["sh", "-c", "python3 inginious-agent-mcq ${BACKEND}"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ARG VERSION=latest | ||
ARG REGISTRY | ||
|
||
FROM ${REGISTRY}/inginious/core-base:${VERSION} | ||
|
||
COPY inginious/backend/ inginious/backend/ | ||
COPY inginious-backend . | ||
|
||
# See https://github.com/pypa/setuptools_scm/#usage-from-docker | ||
RUN --mount=source=.git,target=.git,type=bind \ | ||
pip3 install --no-cache-dir -e . | ||
|
||
CMD ["sh", "-c", "python3 inginious-backend ${AGENT} ${CLIENT}"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from pymongo import MongoClient | ||
from gridfs import GridFS | ||
|
||
from inginious.frontend.user_manager import UserManager | ||
|
||
def try_mongodb_opts(host="localhost", database_name='INGInious'): | ||
""" Try MongoDB configuration """ | ||
try: | ||
mongo_client = MongoClient(host=host) | ||
# Effective access only occurs when we call a method on the connexion | ||
mongo_version = str(mongo_client.server_info()['version']) | ||
print("Found mongodb server running version %s on %s." % (mongo_version, host)) | ||
except Exception as e: | ||
print("Cannot connect to MongoDB on host %s: %s" % (host, str(e))) | ||
return None | ||
|
||
try: | ||
database = mongo_client[database_name] | ||
# Effective access only occurs when we call a method on the database. | ||
database.list_collection_names() | ||
except Exception as e: | ||
print("Cannot access database %s: %s" % (database_name, str(e))) | ||
return None | ||
|
||
try: | ||
# Effective access only occurs when we call a method on the gridfs object. | ||
GridFS(database).find_one() | ||
except Exception as e: | ||
print("Cannot access gridfs %s: %s" % (database_name, str(e))) | ||
return None | ||
|
||
return database | ||
|
||
if __name__ == '__main__': | ||
username = "superadmin" | ||
realname = "INGInious superadmin" | ||
email = "[email protected]" | ||
password = "superadmin" | ||
|
||
print('Initial DB setup.') | ||
|
||
database = try_mongodb_opts('db') | ||
|
||
database.users.insert_one({"username": username, | ||
"realname": realname, | ||
"email": email, | ||
"password": UserManager.hash_password(password), | ||
"bindings": {}, | ||
"language": "en"}) | ||
print('Superadmin user added!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ARG VERSION=latest | ||
ARG REGISTRY | ||
|
||
FROM ${REGISTRY}/inginious/core-base:${VERSION} | ||
|
||
COPY inginious/frontend inginious/frontend/ | ||
COPY inginious/client inginious/client/ | ||
COPY inginious-webapp . | ||
|
||
RUN dnf install -y git gcc python39-devel | ||
|
||
# See https://github.com/pypa/setuptools_scm/#usage-from-docker | ||
RUN --mount=source=.git,target=.git,type=bind \ | ||
pip3 install --no-cache-dir -e . | ||
|
||
COPY deploy/db_setup.py /tmp/db_setup.py | ||
|
||
CMD ["sh", "-c", "python3 /tmp/db_setup.py; python3 inginious-webapp"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Base core container. This is not a service per-se but is used as a common layer for the core services. | ||
FROM rockylinux:8 | ||
|
||
ENV INGINIOUS_COMPOSE=1 | ||
|
||
RUN dnf update -y && dnf install -y python39 python39-pip git | ||
RUN pip3 install importlib-metadata | ||
|
||
WORKDIR /inginious | ||
COPY setup.py README.rst ./ | ||
COPY inginious/common/ inginious/common/ | ||
COPY inginious/__init__.py inginious/ | ||
|
||
# See https://github.com/pypa/setuptools_scm/#usage-from-docker | ||
RUN --mount=source=.git,target=.git,type=bind \ | ||
pip3 install --no-cache-dir -e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
services: | ||
|
||
base: | ||
image: ${REGISTRY}/inginious/core-base:${VERSION} | ||
build: | ||
dockerfile: deploy/inginious-base.containerfile | ||
args: | ||
- VERSION=${VERSION} | ||
- REGISTRY=${REGISTRY} | ||
command: /bin/true | ||
|
||
db: | ||
image: mongo:6.0.2 | ||
networks: | ||
- inginious | ||
|
||
backend: | ||
image: ${REGISTRY}/inginious/core-backend:${VERSION} | ||
depends_on: | ||
- base | ||
build: | ||
dockerfile: deploy/backend.containerfile | ||
args: | ||
- VERSION=${VERSION} | ||
- REGISTRY=${REGISTRY} | ||
environment: | ||
AGENT: "tcp://0.0.0.0:2001" | ||
CLIENT: "tcp://0.0.0.0:2000" | ||
networks: | ||
- inginious | ||
|
||
agent-docker: | ||
image: ${REGISTRY}/inginious/core-agent_docker:${VERSION} | ||
depends_on: | ||
- backend | ||
deploy: | ||
replicas: 1 | ||
build: | ||
dockerfile: deploy/agent-docker.containerfile | ||
args: | ||
- VERSION=${VERSION} | ||
- REGISTRY=${REGISTRY} | ||
environment: | ||
BACKEND: "tcp://backend:2001" | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
# See https://github.com/UCL-INGI/INGInious/issues/352 | ||
- ./tasks/:/inginious/tasks | ||
- ./backups/:/inginious/backups | ||
# See https://github.com/UCL-INGI/INGInious/issues/799 | ||
- /tmp/agent_data/:/tmp/agent_data/ | ||
networks: | ||
- inginious | ||
|
||
agent-mcq: | ||
image: ${REGISTRY}/inginious/core-agent_mcq:${VERSION} | ||
depends_on: | ||
- backend | ||
deploy: | ||
replicas: 1 | ||
build: | ||
dockerfile: deploy/agent-mcq.containerfile | ||
args: | ||
- VERSION=${VERSION} | ||
- REGISTRY=${REGISTRY} | ||
environment: | ||
BACKEND: "tcp://backend:2001" | ||
volumes: | ||
# See https://github.com/UCL-INGI/INGInious/issues/352 | ||
- ./tasks/:/inginious/tasks | ||
- ./backups/:/inginious/backups | ||
# See https://github.com/UCL-INGI/INGInious/issues/799 | ||
- /tmp/agent_data/:/tmp/agent_data/ | ||
networks: | ||
- inginious | ||
|
||
frontend: | ||
image: ${REGISTRY}/inginious/core-frontend:${VERSION} | ||
build: | ||
dockerfile: deploy/frontend.containerfile | ||
args: | ||
- VERSION=${VERSION} | ||
- REGISTRY=${REGISTRY} | ||
depends_on: | ||
- backend | ||
- agent-docker | ||
- agent-mcq | ||
environment: | ||
- INGINIOUS_WEBAPP_HOST=0.0.0.0 | ||
volumes: | ||
- ./configuration.deploy.yaml:/inginious/configuration.yaml | ||
- ./tasks/:/inginious/tasks | ||
- ./backups/:/inginious/backups | ||
ports: | ||
- 9000:8080 | ||
networks: | ||
- inginious | ||
|
||
networks: | ||
inginious: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters