aboutsummaryrefslogtreecommitdiffstats
path: root/docker
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-24 15:58:16 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-24 19:26:47 +0200
commitd46a69a43f5662947a81286adcb8f452163cfdf5 (patch)
treeb6251a20d2979f019b45d9ee5bec16ef3011799c /docker
parentfix(frontend): Algolia search (diff)
downloadrefinery-d46a69a43f5662947a81286adcb8f452163cfdf5.tar.gz
refinery-d46a69a43f5662947a81286adcb8f452163cfdf5.tar.zst
refinery-d46a69a43f5662947a81286adcb8f452163cfdf5.zip
build: create Docker images automatically
Diffstat (limited to 'docker')
-rw-r--r--docker/.gitignore5
-rwxr-xr-xdocker/bake.sh17
-rwxr-xr-xdocker/build.sh48
-rw-r--r--docker/context/Dockerfile.base (renamed from docker/Dockerfile.base)11
-rw-r--r--docker/context/Dockerfile.cli (renamed from docker/Dockerfile.cli)8
-rw-r--r--docker/context/Dockerfile.web (renamed from docker/Dockerfile.web)8
-rw-r--r--docker/context/docker-bake.hcl43
-rw-r--r--docker/docker-bake.hcl44
-rwxr-xr-xdocker/get_version.sh9
-rwxr-xr-xdocker/prepare_context.sh66
10 files changed, 156 insertions, 103 deletions
diff --git a/docker/.gitignore b/docker/.gitignore
new file mode 100644
index 00000000..64089f92
--- /dev/null
+++ b/docker/.gitignore
@@ -0,0 +1,5 @@
1# SPDX-FileCopyrightText: 2024 The Refinery Authors
2#
3# SPDX-License-Identifier: CC0-1.0
4
5context/extracted
diff --git a/docker/bake.sh b/docker/bake.sh
new file mode 100755
index 00000000..67b05a52
--- /dev/null
+++ b/docker/bake.sh
@@ -0,0 +1,17 @@
1#!/usr/bin/env bash
2
3# SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
4#
5# SPDX-License-Identifier: EPL-2.0
6
7set -euo pipefail
8
9REFINERY_VERSION="$(./get_version.sh)"
10export REFINERY_VERSION
11
12export REFINERY_PUSH="${1-false}"
13
14export SOURCE_DATE_EPOCH=0
15
16cd context
17exec docker buildx bake -f docker-bake.hcl "${@:2}"
diff --git a/docker/build.sh b/docker/build.sh
index 8a03e6d5..2f5ba270 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -1,6 +1,6 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2 2
3# SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/> 3# SPDX-FileCopyrightText: 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
@@ -8,48 +8,6 @@ set -euo pipefail
8 8
9(cd .. && ./gradlew distTar) 9(cd .. && ./gradlew distTar)
10 10
11refinery_version="$(grep '^version=' ../gradle.properties | cut -d'=' -f2)" 11./prepare_context.sh
12cli_distribution_name="refinery-generator-cli-${refinery_version}"
13web_distribution_name="refinery-language-web-${refinery_version}"
14 12
15rm -rf "${cli_distribution_name}" "${web_distribution_name}" {cli,web}_dist \ 13./bake.sh "${1-false}" "${@:2}"
16 {cli,web}_{,app_}lib common_{,amd64_,arm64_}lib {cli,web}_{amd64,arm64}_bin
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
36
37# Move architecture-specific jars to their repsective directories.
38mv common_lib/ortools-linux-x86-64-*.jar common_amd64_lib
39mv common_lib/ortools-linux-aarch64-*.jar common_arm64_lib
40rm common_lib/ortools-{darwin,win32}-*.jar
41# Move the applications jars for the dependencies into a separate Docker layer
42# to enable faster updates.
43mv cli_dist/lib/* cli_lib
44mv web_dist/lib/* web_lib
45# Omit references to jars not present for the current architecture from the
46# startup scripts.
47sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' cli_dist/bin/refinery-generator-cli > cli_amd64_bin/refinery-generator-cli
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
49chmod a+x cli_{amd64,arm64}_bin/refinery-generator-cli
50sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' web_dist/bin/refinery-language-web > web_amd64_bin/refinery-language-web
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
52chmod a+x web_{amd64,arm64}_bin/refinery-language-web
53rm -rf {cli,web}_dist
54
55REFINERY_VERSION="${refinery_version}" docker buildx bake -f docker-bake.hcl
diff --git a/docker/Dockerfile.base b/docker/context/Dockerfile.base
index 0668ce78..c73f2c4c 100644
--- a/docker/Dockerfile.base
+++ b/docker/context/Dockerfile.base
@@ -30,8 +30,8 @@ RUN apt-get update && \
30 ln -sf /usr/bin/x86_64-linux-gnu-objcopy /usr/bin/objcopy && \ 30 ln -sf /usr/bin/x86_64-linux-gnu-objcopy /usr/bin/objcopy && \
31 rm -rf /var/lib/apt/lists/* 31 rm -rf /var/lib/apt/lists/*
32 32
33FROM --platform=$BUILDPLATFORM jlink-$TARGETARCH-on-$BUILDARCH as jlink 33FROM --platform=$BUILDPLATFORM jlink-$TARGETARCH-on-$BUILDARCH AS jlink
34RUN jlink --no-header-files --no-man-pages --compress=2 \ 34RUN jlink --no-header-files --no-man-pages \
35 --module-path=/crossjdk/jmods --strip-debug --add-modules \ 35 --module-path=/crossjdk/jmods --strip-debug --add-modules \
36 java.base,java.logging,java.xml,jdk.zipfs \ 36 java.base,java.logging,java.xml,jdk.zipfs \
37 --output /jlink 37 --output /jlink
@@ -44,15 +44,14 @@ 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 common_lib /app/lib 47ADD --link extracted/common_lib /app/lib
48 48
49FROM base AS base-amd64 49FROM base AS base-amd64
50# Layer with platform-dependent dependencies, slow changing. 50# Layer with platform-dependent dependencies, slow changing.
51ADD --link common_amd64_lib /app/lib 51ADD --link extracted/common_amd64_lib /app/lib
52 52
53FROM base AS base-arm64 53FROM base AS base-arm64
54# Layer with platform-dependent dependencies, slow changing. 54# Layer with platform-dependent dependencies, slow changing.
55ADD --link common_arm64_lib /app/lib 55ADD --link extracted/common_arm64_lib /app/lib
56 56
57FROM base-$TARGETARCH 57FROM base-$TARGETARCH
58
diff --git a/docker/Dockerfile.cli b/docker/context/Dockerfile.cli
index 54396d4e..ddfb6b29 100644
--- a/docker/Dockerfile.cli
+++ b/docker/context/Dockerfile.cli
@@ -4,21 +4,21 @@
4 4
5FROM base AS cli-base 5FROM base AS cli-base
6# Layer with platform-dependent dependencies, slow changing. 6# Layer with platform-dependent dependencies, slow changing.
7ADD --link cli_lib /app/lib 7ADD --link extracted/cli_lib /app/lib
8 8
9FROM cli-base AS cli-amd64 9FROM cli-base AS cli-amd64
10# Layer with platform-dependent startup script containing references to all 10# Layer with platform-dependent startup script containing references to all
11# dependency versions. 11# dependency versions.
12ADD --link cli_amd64_bin /app/bin 12ADD --link extracted/cli_amd64_bin /app/bin
13 13
14FROM cli-base AS cli-arm64 14FROM cli-base AS cli-arm64
15# Layer with platform-dependent startup script containing references to all 15# Layer with platform-dependent startup script containing references to all
16# dependency versions. 16# dependency versions.
17ADD --link cli_arm64_bin /app/bin 17ADD --link extracted/cli_arm64_bin /app/bin
18 18
19FROM cli-$TARGETARCH 19FROM cli-$TARGETARCH
20# Layer with platform-independent application jars. 20# Layer with platform-independent application jars.
21ADD --link cli_app_lib /app/lib 21ADD --link extracted/cli_app_lib /app/lib
22# Common settings added on top. 22# Common settings added on top.
23ENV REFINERY_LIBRARY_PATH=/data 23ENV REFINERY_LIBRARY_PATH=/data
24USER 1000 24USER 1000
diff --git a/docker/Dockerfile.web b/docker/context/Dockerfile.web
index dd25662e..9c2874c8 100644
--- a/docker/Dockerfile.web
+++ b/docker/context/Dockerfile.web
@@ -4,21 +4,21 @@
4 4
5FROM base AS web-base 5FROM base AS web-base
6# Layer with platform-dependent dependencies, slow changing. 6# Layer with platform-dependent dependencies, slow changing.
7ADD --link web_lib /app/lib 7ADD --link extracted/web_lib /app/lib
8 8
9FROM web-base AS web-amd64 9FROM web-base AS web-amd64
10# Layer with platform-dependent startup script containing references to all 10# Layer with platform-dependent startup script containing references to all
11# dependency versions. 11# dependency versions.
12ADD --link web_amd64_bin /app/bin 12ADD --link extracted/web_amd64_bin /app/bin
13 13
14FROM web-base AS web-arm64 14FROM web-base AS web-arm64
15# Layer with platform-dependent startup script containing references to all 15# Layer with platform-dependent startup script containing references to all
16# dependency versions. 16# dependency versions.
17ADD --link web_arm64_bin /app/bin 17ADD --link extracted/web_arm64_bin /app/bin
18 18
19FROM web-$TARGETARCH 19FROM web-$TARGETARCH
20# Layer with platform-independent application jars. 20# Layer with platform-independent application jars.
21ADD --link web_app_lib /app/lib 21ADD --link extracted/web_app_lib /app/lib
22# Common settings added on top. 22# Common settings added on top.
23ENV REFINERY_LISTEN_HOST=0.0.0.0 REFINERY_LISTEN_PORT=8888 23ENV REFINERY_LISTEN_HOST=0.0.0.0 REFINERY_LISTEN_PORT=8888
24EXPOSE 8888 24EXPOSE 8888
diff --git a/docker/context/docker-bake.hcl b/docker/context/docker-bake.hcl
new file mode 100644
index 00000000..3c388627
--- /dev/null
+++ b/docker/context/docker-bake.hcl
@@ -0,0 +1,43 @@
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
9variable "REFINERY_PUSH" {
10 default = "false"
11}
12
13group "default" {
14 targets = ["cli", "web"]
15}
16
17target "base" {
18 dockerfile = "Dockerfile.base"
19 platforms = ["linux/amd64", "linux/arm64"]
20 output = ["type=cacheonly"]
21}
22
23target "cli" {
24 dockerfile = "Dockerfile.cli"
25 platforms = ["linux/amd64", "linux/arm64"]
26 output = [
27 "type=image,push=${REFINERY_PUSH},\"name=ghcr.io/graphs4value/refinery-cli:${REFINERY_VERSION},ghcr.io/graphs4value/refinery-cli:latest\",annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,\"annotation-index.org.opencontainers.image.description=Command line interface for Refinery, an efficient graph solver for generating well-formed models\",annotation-index.org.opencontainers.image.licenses=EPL-2.0"
28 ]
29 contexts = {
30 base = "target:base"
31 }
32}
33
34target "web" {
35 dockerfile = "Dockerfile.web"
36 platforms = ["linux/amd64", "linux/arm64"]
37 output = [
38 "type=image,push=${REFINERY_PUSH},\"name=ghcr.io/graphs4value/refinery:${REFINERY_VERSION},ghcr.io/graphs4value/refinery:latest\",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"
39 ]
40 contexts = {
41 base = "target:base"
42 }
43}
diff --git a/docker/docker-bake.hcl b/docker/docker-bake.hcl
deleted file mode 100644
index 0a84e0a3..00000000
--- a/docker/docker-bake.hcl
+++ /dev/null
@@ -1,44 +0,0 @@
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
9variable "REFINERY_ANNOTATIONS" {
10 default = ""
11}
12
13group "default" {
14 targets = ["cli", "web"]
15}
16
17target "base" {
18 dockerfile = "Dockerfile.base"
19 platforms = ["linux/amd64", "linux/arm64"]
20 output = ["type=cacheonly"]
21}
22
23target "cli" {
24 dockerfile = "Dockerfile.cli"
25 platforms = ["linux/amd64", "linux/arm64"]
26 output = [
27 "type=image,\"name=ghcr.io/graphs4value/refinery-cli:${REFINERY_VERSION},ghcr.io/graphs4value/refinery-cli:latest\",push=true,annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,\"annotation-index.org.opencontainers.image.description=Command line interface for Refinery, an efficient graph solver for generating well-formed models\",annotation-index.org.opencontainers.image.licenses=EPL-2.0"
28 ]
29 contexts = {
30 base = "target:base"
31 }
32}
33
34target "web" {
35 dockerfile = "Dockerfile.web"
36 platforms = ["linux/amd64", "linux/arm64"]
37 output = [
38 "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"
39
40 ]
41 contexts = {
42 base = "target:base"
43 }
44}
diff --git a/docker/get_version.sh b/docker/get_version.sh
new file mode 100755
index 00000000..f507d060
--- /dev/null
+++ b/docker/get_version.sh
@@ -0,0 +1,9 @@
1#!/usr/bin/env bash
2
3# SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
4#
5# SPDX-License-Identifier: EPL-2.0
6
7set -euo pipefail
8
9grep '^version=' ../gradle.properties | cut -d'=' -f2
diff --git a/docker/prepare_context.sh b/docker/prepare_context.sh
new file mode 100755
index 00000000..ca8bf500
--- /dev/null
+++ b/docker/prepare_context.sh
@@ -0,0 +1,66 @@
1#!/usr/bin/env bash
2
3# SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
4#
5# SPDX-License-Identifier: EPL-2.0
6
7set -euo pipefail
8
9refinery_version="$(./get_version.sh)"
10cli_distribution_name="refinery-generator-cli-${refinery_version}"
11web_distribution_name="refinery-language-web-${refinery_version}"
12
13rm -rf "${cli_distribution_name}" "${web_distribution_name}" {cli,web}_dist context/extracted
14
15tar -xvf "../subprojects/generator-cli/build/distributions/${cli_distribution_name}.tar"
16mv "${cli_distribution_name}" cli_dist
17tar -xvf "../subprojects/language-web/build/distributions/${web_distribution_name}.tar"
18mv "${web_distribution_name}" web_dist
19mkdir -p context/extracted/{cli,web}_{,app_}lib \
20 context/extracted/common_{,amd64_,arm64_}lib \
21 context/extracted/{cli,web}_{amd64,arm64}_bin
22
23move_application_jars() {
24 prefix="$1"
25 # Our application itself is very small, so it will get added as the last layer
26 # of both containers.
27 mv "${prefix}"_dist/lib/refinery-* "context/extracted/${prefix}_app_lib"
28}
29
30move_application_jars cli
31move_application_jars web
32
33for i in cli_dist/lib/*; do
34 j="web${i#cli}"
35 if [[ -f "$j" ]]; then
36 mv "$i" "context/extracted/common_lib${i#cli_dist/lib}"
37 rm "$j"
38 fi
39done
40
41# Move architecture-specific jars to their repsective directories.
42mv context/extracted/common_lib/ortools-linux-x86-64-*.jar context/extracted/common_amd64_lib
43mv context/extracted/common_lib/ortools-linux-aarch64-*.jar context/extracted/common_arm64_lib
44rm context/extracted/common_lib/ortools-{darwin,win32}-*.jar
45
46prepare_application() {
47 prefix="$1"
48 suffix="$2"
49 # Move the applications jars for the dependencies into a separate Docker layer
50 # to enable faster updates.
51 mv "${prefix}"_dist/lib/* "context/extracted/${prefix}_lib"
52 # Omit references to jars not present for the current architecture from the
53 # startup scripts.
54 sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' \
55 "${prefix}_dist/bin/refinery-${suffix}" \
56 > "context/extracted/${prefix}_amd64_bin/refinery-${suffix}"
57 sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' \
58 "${prefix}_dist/bin/refinery-${suffix}" \
59 > "context/extracted/${prefix}_arm64_bin/refinery-${suffix}"
60 chmod a+x "context/extracted/${prefix}"_{amd64,arm64}_bin/refinery-"${suffix}"
61}
62
63prepare_application cli generator-cli
64prepare_application web language-web
65
66rm -rf {cli,web}_dist