Skip to content

Commit

Permalink
build(docker): mergeable compose files reduce number of files to main…
Browse files Browse the repository at this point in the history
…tain

Instead of writing multiple compose files independently, one basic file and one with the extensions for development can be merged on CLI
  • Loading branch information
GiugAles committed Jan 12, 2024
1 parent a97b168 commit a3e492a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 58 deletions.
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Yggdrasil build configuration
YGGDRASIL_VERSION=0.0.0
# Build environment preparation
LANG=C.UTF-8
42 changes: 9 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.

28 changes: 12 additions & 16 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -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"



4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a3e492a

Please sign in to comment.