From a3e492abe93ac30f76054e1eef70f6d43fd7938e Mon Sep 17 00:00:00 2001 From: Alessandro Giugno Date: Fri, 12 Jan 2024 15:19:44 +0100 Subject: [PATCH] build(docker): mergeable compose files reduce number of files to maintain Instead of writing multiple compose files independently, one basic file and one with the extensions for development can be merged on CLI --- .devcontainer/devcontainer.json | 3 +-- .env | 4 ++++ Dockerfile | 42 +++++++-------------------------- README.md | 16 ++++++++----- docker-compose-dev.yml | 28 ++++++++++------------ docker-compose.yml | 4 +++- 6 files changed, 39 insertions(+), 58 deletions(-) create mode 100644 .env diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 92623d2d..672ff3ce 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,7 @@ { "name": "[Optional] Your project name here", - "dockerComposeFile": "../docker-compose-dev.yml", + "dockerComposeFile": ["../docker-compose.yml", "../docker-compose-dev.yml"], "service": "yggdrasil", "workspaceFolder": "/opt/app/", - "postCreateCommand": "./gradlew", "shutdownAction": "stopCompose" } diff --git a/.env b/.env new file mode 100644 index 00000000..b6c3780f --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +# Yggdrasil build configuration +YGGDRASIL_VERSION=0.0.0 +# Build environment preparation +LANG=C.UTF-8 diff --git a/Dockerfile b/Dockerfile index ae4744a3..7408f99e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,45 +1,21 @@ FROM eclipse-temurin:21 as builder -# Yggdrasil build configuration -ENV YGGDRASIL_VERSION 0.0.0 -# Enable building specific branches -ARG YGGDRASIL_BRANCH="main" - -# Build environment preparation -ENV LANG C.UTF-8 - -RUN apt update && apt install -y \ - git \ - && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* - -RUN echo ${YGGDRASIL_BRANCH} -RUN git clone https://github.com/Interactions-HSG/yggdrasil.git \ - --branch $YGGDRASIL_BRANCH \ - # only the specified branch - --depth=1 \ - /opt/app +ADD . /opt/app/ WORKDIR /opt/app/ RUN ./gradlew FROM eclipse-temurin:21 -# Yggdrasil build configuration -ENV YGGDRASIL_VERSION 0.0.0 +RUN apt update && apt install -y \ + git \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* -# Build environment preparation -ENV LANG C.UTF-8 +ARG YGGDRASIL_VERSION -# Copy the jar -RUN mkdir /opt/app -COPY --from=builder /opt/app/build/libs/yggdrasil-${YGGDRASIL_VERSION}-SNAPSHOT-all.jar /opt/app -# Copy the configuration -RUN mkdir /opt/app/conf +# https://stackoverflow.com/a/793867 +RUN mkdir -p /opt/app/conf +COPY --from=builder /opt/app/build/libs/yggdrasil-${YGGDRASIL_VERSION}-SNAPSHOT-all.jar /opt/app/libs/ COPY --from=builder /opt/app/conf/docker_disk_config.json /opt/app/conf/config.json -# The default http port -EXPOSE 8080 -# The port for interacting with CArtAgO -EXPOSE 8088 - -ENTRYPOINT java -jar /opt/app/yggdrasil-${YGGDRASIL_VERSION}-SNAPSHOT-all.jar +ENTRYPOINT java -jar /opt/app/libs/yggdrasil-${YGGDRASIL_VERSION}-SNAPSHOT-all.jar diff --git a/README.md b/README.md index 009916d9..384ed572 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ Lecture Notes in Computer Science, vol 11375. Springer, Cham. https://doi.org/10 [2] Alessandro Ricci, Michele Piunti, and Mirko Viroli. 2011. Environment Programming in multi-agent systems: an artifact-based perspective. Autonomous Agents and Multi-Agent Systems, 23(2):158-192. - ## Prerequisites * JDK 21+ @@ -32,7 +31,6 @@ To build the project, just use: The default Gradle task `shadowJar` generates a fat-jar in the `build/libs` directory. - ## Running Yggdrasil To start an Yggdrasil node: @@ -58,6 +56,13 @@ Run with docker-compose (by default, it exposes the port `8899` of the host mach docker-compose up ``` +Use `docker-compose-dev.yml` for an environment that contains both libraries and sources: + +```shell +docker-compose -f docker-compose.yml -f docker-compose-dev.yml build +docker-compose -f docker-compose.yml -f docker-compose-dev.yml up +``` + ## HTTP API Overview The HTTP API implements CRUD operations for 2 types of resources: @@ -110,10 +115,9 @@ Using the discovered hub and topic IRIs, a client can subscribe for notification that contains a JSON payload with the following fields (see the [W3C WebSub recommendation](https://www.w3.org/TR/2018/REC-websub-20180123/)): - * `hub.mode` - * `hub.topic` - * `hub.callback` +* `hub.mode` +* `hub.topic` +* `hub.callback` When a resource is updated, Yggdrasil issues `POST` requests with the (updated) resource representation to all registered callbacks. - diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index abc3fadd..622f325d 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,21 +1,17 @@ version: '3.9' +# This file adds extensions needed for development and needs to be merged with docker-compose.yml +# See https://docs.docker.com/compose/multiple-compose-files/merge/ services: yggdrasil: - image: yggdrasil:dev - build: - context: . - dockerfile: Dockerfile_Dev - tty: true - container_name: yggdrasil + # overwrite entrypoint of productive image + entrypoint: ["tail", "-F", "anything"] + container_name: yggdrasil-dev + # Sync changes with host volumes: - - .:/opt/app/:cached -# # create a project volume to keep work -# # check if git can change line endings automatically -# - .:/opt/app/y:cached - environment: - - YGGDRASIL_VERSION=0.0.0 - - GRADLE_TASK=${GRADLE_TASK} - ports: - - "8899:8080" - - "8900:8088" + - .:/opt/app/:cached # does already exist but https://stackoverflow.com/a/39647631 + # restarting causes problems when using vscode's "Reopne in Container" + restart: "no" + + + diff --git a/docker-compose.yml b/docker-compose.yml index dcf34c23..8ff3dd71 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,11 @@ services: image: yggdrasil:latest build: context: . + args: + - YGGDRASIL_VERSION=${YGGDRASIL_VERSION} container_name: yggdrasil environment: - - YGGDRASIL_VERSION=0.0.0 + - YGGDRASIL_VERSION=${YGGDRASIL_VERSION} ports: - "8899:8080" - "8900:8088"