aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-02 14:49:14 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-02 18:00:52 +0200
commit57384ceca30234336b1ab4ada00a4ab1212bd78c (patch)
treec8cda58d62e51a291d9e49585ef65c9bd5ffccde
parentbuild: set Gradle JVM version (diff)
downloadrefinery-57384ceca30234336b1ab4ada00a4ab1212bd78c.tar.gz
refinery-57384ceca30234336b1ab4ada00a4ab1212bd78c.tar.zst
refinery-57384ceca30234336b1ab4ada00a4ab1212bd78c.zip
build: publish CLI as Docker container
-rw-r--r--docker/Dockerfile.base (renamed from docker/Dockerfile)29
-rw-r--r--docker/Dockerfile.cli26
-rw-r--r--docker/Dockerfile.web27
-rwxr-xr-xdocker/build.sh62
-rw-r--r--docker/docker-bake.hcl39
5 files changed, 139 insertions, 44 deletions
diff --git a/docker/Dockerfile b/docker/Dockerfile.base
index 6cb4d71c..0668ce78 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile.base
@@ -1,4 +1,4 @@
1# SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> 1# SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
2# 2#
3# SPDX-License-Identifier: EPL-2.0 3# SPDX-License-Identifier: EPL-2.0
4 4
@@ -44,28 +44,15 @@ RUN dnf install -y findutils && \
44COPY --link --from=jlink /jlink /usr/lib/java 44COPY --link --from=jlink /jlink /usr/lib/java
45ENV JAVA_HOME="/usr/lib/java" PATH="/usr/lib/java/bin:${PATH}" 45ENV JAVA_HOME="/usr/lib/java" PATH="/usr/lib/java/bin:${PATH}"
46# Layer with platform-independent dependencies, slow changing. 46# Layer with platform-independent dependencies, slow changing.
47ADD --link lib /app/lib 47ADD --link common_lib /app/lib
48 48
49FROM base AS refinery-amd64 49FROM base AS base-amd64
50# Layer with platform-dependent dependencies, slow changing. 50# Layer with platform-dependent dependencies, slow changing.
51ADD --link lib_amd64 /app/lib 51ADD --link common_amd64_lib /app/lib
52# Layer with platform-dependent startup script containing references to all
53# dependency version.
54ADD --link app_amd64_bin /app/bin
55 52
56FROM base AS refinery-arm64 53FROM base AS base-arm64
57# Layer with platform-dependent dependencies, slow changing. 54# Layer with platform-dependent dependencies, slow changing.
58ADD --link lib_arm64 /app/lib 55ADD --link common_arm64_lib /app/lib
59# Layer with platform-dependent startup script containing references to all 56
60# dependency version. 57FROM base-$TARGETARCH
61ADD --link app_arm64_bin /app/bin
62 58
63FROM refinery-$TARGETARCH
64# Layer with platform-independent application jars.
65ADD --link app_lib /app/lib
66# Common settings added on top.
67ENV REFINERY_LISTEN_HOST=0.0.0.0 REFINERY_LISTEN_PORT=8888
68EXPOSE 8888
69USER 1000
70WORKDIR /app
71ENTRYPOINT /app/bin/refinery-language-web
diff --git a/docker/Dockerfile.cli b/docker/Dockerfile.cli
new file mode 100644
index 00000000..54396d4e
--- /dev/null
+++ b/docker/Dockerfile.cli
@@ -0,0 +1,26 @@
1# SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
2#
3# SPDX-License-Identifier: EPL-2.0
4
5FROM base AS cli-base
6# Layer with platform-dependent dependencies, slow changing.
7ADD --link cli_lib /app/lib
8
9FROM cli-base AS cli-amd64
10# Layer with platform-dependent startup script containing references to all
11# dependency versions.
12ADD --link cli_amd64_bin /app/bin
13
14FROM cli-base AS cli-arm64
15# Layer with platform-dependent startup script containing references to all
16# dependency versions.
17ADD --link cli_arm64_bin /app/bin
18
19FROM cli-$TARGETARCH
20# Layer with platform-independent application jars.
21ADD --link cli_app_lib /app/lib
22# Common settings added on top.
23ENV REFINERY_LIBRARY_PATH=/data
24USER 1000
25WORKDIR /data
26ENTRYPOINT ["/app/bin/refinery-generator-cli"]
diff --git a/docker/Dockerfile.web b/docker/Dockerfile.web
new file mode 100644
index 00000000..dd25662e
--- /dev/null
+++ b/docker/Dockerfile.web
@@ -0,0 +1,27 @@
1# SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
2#
3# SPDX-License-Identifier: EPL-2.0
4
5FROM base AS web-base
6# Layer with platform-dependent dependencies, slow changing.
7ADD --link web_lib /app/lib
8
9FROM web-base AS web-amd64
10# Layer with platform-dependent startup script containing references to all
11# dependency versions.
12ADD --link web_amd64_bin /app/bin
13
14FROM web-base AS web-arm64
15# Layer with platform-dependent startup script containing references to all
16# dependency versions.
17ADD --link web_arm64_bin /app/bin
18
19FROM web-$TARGETARCH
20# Layer with platform-independent application jars.
21ADD --link web_app_lib /app/lib
22# Common settings added on top.
23ENV REFINERY_LISTEN_HOST=0.0.0.0 REFINERY_LISTEN_PORT=8888
24EXPOSE 8888
25USER 1000
26WORKDIR /app
27ENTRYPOINT ["/app/bin/refinery-language-web"]
diff --git a/docker/build.sh b/docker/build.sh
index 6ddd0cc7..8a03e6d5 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -1,39 +1,55 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2 2
3# SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> 3# SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
4# 4#
5# SPDX-License-Identifier: EPL-2.0 5# SPDX-License-Identifier: EPL-2.0
6 6
7set -euo pipefail 7set -euo pipefail
8 8
9(cd .. && ./gradlew :refinery-language-web:distTar) 9(cd .. && ./gradlew distTar)
10 10
11refinery_version="$(grep '^version=' ../gradle.properties | cut -d'=' -f2)" 11refinery_version="$(grep '^version=' ../gradle.properties | cut -d'=' -f2)"
12distribution_name="refinery-language-web-${refinery_version}" 12cli_distribution_name="refinery-generator-cli-${refinery_version}"
13rm -rf "${distribution_name}" dist app_lib app_{amd64,arm64}_bin lib lib_{amd64,arm64} 13web_distribution_name="refinery-language-web-${refinery_version}"
14 14
15tar -xf "../subprojects/language-web/build/distributions/${distribution_name}.tar" 15rm -rf "${cli_distribution_name}" "${web_distribution_name}" {cli,web}_dist \
16mv "${distribution_name}" dist 16 {cli,web}_{,app_}lib common_{,amd64_,arm64_}lib {cli,web}_{amd64,arm64}_bin
17mkdir -p app_lib app_{amd64,arm64}_bin lib lib_{amd64,arm64} 17
18tar -xf "../subprojects/generator-cli/build/distributions/${cli_distribution_name}.tar"
19mv "${cli_distribution_name}" cli_dist
20tar -xf "../subprojects/language-web/build/distributions/${web_distribution_name}.tar"
21mv "${web_distribution_name}" web_dist
22mkdir -p {cli,web}_{,app_}lib common_{,amd64_,arm64_}lib {cli,web}_{amd64,arm64}_bin
23
24# Our application itself is very small, so it will get added as the last layer
25# of both containers.
26mv cli_dist/lib/refinery-* cli_app_lib
27mv web_dist/lib/refinery-* web_app_lib
28
29for i in cli_dist/lib/*; do
30 j="web${i#cli}"
31 if [[ -f "$j" ]]; then
32 mv "$i" "common_lib${i#cli_dist/lib}"
33 rm "$j"
34 fi
35done
18 36
19# Move architecture-specific jars to their repsective directories. 37# Move architecture-specific jars to their repsective directories.
20mv dist/lib/ortools-linux-x86-64-*.jar lib_amd64 38mv common_lib/ortools-linux-x86-64-*.jar common_amd64_lib
21mv dist/lib/ortools-linux-aarch64-*.jar lib_arm64 39mv common_lib/ortools-linux-aarch64-*.jar common_arm64_lib
22rm dist/lib/ortools-{darwin,win32}-*.jar 40rm common_lib/ortools-{darwin,win32}-*.jar
23# Move the applications jars for the dependencies into a separate Docker layer 41# Move the applications jars for the dependencies into a separate Docker layer
24# to enable faster updates. 42# to enable faster updates.
25mv dist/lib/refinery-* app_lib 43mv cli_dist/lib/* cli_lib
26mv dist/lib/* lib 44mv web_dist/lib/* web_lib
27# Omit references to jars not present for the current architecture from the 45# Omit references to jars not present for the current architecture from the
28# startup scripts. 46# startup scripts.
29sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' dist/bin/refinery-language-web > app_amd64_bin/refinery-language-web 47sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' cli_dist/bin/refinery-generator-cli > cli_amd64_bin/refinery-generator-cli
30sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' dist/bin/refinery-language-web > app_arm64_bin/refinery-language-web 48sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' cli_dist/bin/refinery-generator-cli > cli_arm64_bin/refinery-generator-cli
31chmod a+x app_{amd64,arm64}_bin/refinery-language-web 49chmod a+x cli_{amd64,arm64}_bin/refinery-generator-cli
32rm -rf dist 50sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' web_dist/bin/refinery-language-web > web_amd64_bin/refinery-language-web
33 51sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' web_dist/bin/refinery-language-web > web_arm64_bin/refinery-language-web
34docker buildx build . \ 52chmod a+x web_{amd64,arm64}_bin/refinery-language-web
35 --platform linux/amd64,linux/arm64 \ 53rm -rf {cli,web}_dist
36 --output "type=image,\"name=ghcr.io/graphs4value/refinery:${refinery_version},ghcr.io/graphs4value/refinery:latest\",push=true,annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,annotation-index.org.opencontainers.image.description=Refinery: an efficient graph solver for generating well-formed models,annotation-index.org.opencontainers.image.licenses=EPL-2.0" \ 54
37 --label 'org.opencontainers.image.source=https://github.com/graphs4value/refinery' \ 55REFINERY_VERSION="${refinery_version}" docker buildx bake -f docker-bake.hcl
38 --label 'org.opencontainers.image.description=Refinery: an efficient graph solver for generating well-formed models' \
39 --label 'org.opencontainers.image.licenses=EPL-2.0'
diff --git a/docker/docker-bake.hcl b/docker/docker-bake.hcl
new file mode 100644
index 00000000..b02c82d1
--- /dev/null
+++ b/docker/docker-bake.hcl
@@ -0,0 +1,39 @@
1# SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
2#
3# SPDX-License-Identifier: EPL-2.0
4
5variable "REFINERY_VERSION" {
6 default = ""
7}
8
9group "default" {
10 targets = ["cli", "web"]
11}
12
13target "base" {
14 dockerfile = "Dockerfile.base"
15 platforms = ["linux/amd64", "linux/arm64"]
16 output = ["type=cacheonly"]
17}
18
19target "cli" {
20 dockerfile = "Dockerfile.cli"
21 platforms = ["linux/amd64", "linux/arm64"]
22 output = [
23 "type=image,\"name=ghcr.io/graphs4value/refinery:cli-${REFINERY_VERSION},ghcr.io/graphs4value/refinery:cli\",push=true,annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,annotation-index.org.opencontainers.image.description=Refinery: an efficient graph solver for generating well-formed models,annotation-index.org.opencontainers.image.licenses=EPL-2.0"
24 ]
25 contexts = {
26 base = "target:base"
27 }
28}
29
30target "web" {
31 dockerfile = "Dockerfile.web"
32 platforms = ["linux/amd64", "linux/arm64"]
33 output = [
34 "type=image,\"name=ghcr.io/graphs4value/refinery:${REFINERY_VERSION},ghcr.io/graphs4value/refinery:latest\",push=true,annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,annotation-index.org.opencontainers.image.description=Refinery: an efficient graph solver for generating well-formed models,annotation-index.org.opencontainers.image.licenses=EPL-2.0"
35 ]
36 contexts = {
37 base = "target:base"
38 }
39}