Skip to content

Commit 04d5016

Browse files
DickPostmaDickPostmamswertzYpeZharmbrugge
authored
Refactor: Improve docker builds & Update to java21 (#4811)
* Refactor: Improve docker builds * Refactor: Improve non-root security * Add pip3 integration * Updated base image * build: update to java 21 * update docs for java 21 * fix: set allowed mismatched to 10ms in snowflake id test --------- Co-authored-by: DickPostma <(ID)+(username)@users.noreply.github.com> Co-authored-by: Morris Swertz <[email protected]> Co-authored-by: YpeZ <[email protected]> Co-authored-by: Harm Brugge <[email protected]>
1 parent c906012 commit 04d5016

File tree

9 files changed

+68
-61
lines changed

9 files changed

+68
-61
lines changed

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ orbs:
2121
definitions:
2222
build_config: &build_config
2323
docker:
24-
- image: molgenis/ci-build:1.2.4
24+
- image: molgenis/ci-build:1.3.3
2525
working_directory: ~/repo
2626
resource_class: large
2727
environment:
@@ -30,7 +30,7 @@ definitions:
3030
TERM: dumb
3131
test_config: &test_config
3232
docker:
33-
- image: molgenis/ci-build:1.2.4
33+
- image: molgenis/ci-build:1.3.3
3434
- image: postgres:15-alpine
3535
environment:
3636
POSTGRES_USER: postgres
@@ -44,7 +44,7 @@ definitions:
4444
TERM: dumb
4545
release_config: &release_config
4646
docker:
47-
- image: molgenis/ci-build:1.2.4
47+
- image: molgenis/ci-build:1.3.3
4848
- image: postgres:15-alpine
4949
environment:
5050
POSTGRES_USER: postgres

Dockerfile

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
FROM eclipse-temurin:17.0.11_9-jdk-jammy
1+
FROM ubuntu:24.10
2+
3+
RUN apt update && apt -y upgrade
4+
RUN apt update && apt -y install python3 python3-pip python3-venv openjdk-21-jre-headless
5+
26
ARG JAR_FILE
37
COPY ${JAR_FILE} app.jar
48
EXPOSE 8080
5-
RUN apt-get update && apt-get install python3 python3-venv -y
9+
RUN useradd -m molgenis
10+
11+
USER molgenis
612
ENTRYPOINT ["java","-jar","app.jar"]

azure-pipelines.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ steps:
3636
sudo update-alternatives --display java
3737
displayName: list available java versions (for debug purposes)
3838
- script: |
39-
export JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-amd64/
39+
export JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64/
4040
./gradlew -version
4141
./gradlew test jacocoMergedReport
4242
# sonarqube -Dsonar.login=$(SONAR_TOKEN) -Dsonar.organization=molgenis -Dsonar.host.url=https://sonarcloud.io -Dorg.ajoberstar.grgit.auth.username=$(GITHUB_TOKEN) -Dorg.ajoberstar.grgit.auth.password
43-
displayName: run test, ensure we are using java 17 JAVA_HOME
43+
displayName: run test, ensure we are using java 21 JAVA_HOME
4444

4545
env:
4646
MOLGENIS_POSTGRES_USER: molgenis

backend/molgenis-emx2-sql/src/test/java/org/molgenis/emx2/sql/SnowflakeIdGeneratorTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void testExtractTimestampFromSnowflake() {
9191
String snowflakeId = generator.generateId();
9292

9393
long snowflakeTimestamp = SnowflakeIdGenerator.extractTimestamp(snowflakeId);
94-
// Allow a mismatch of 1ms
95-
assertTrue(Math.abs(currentTime - snowflakeTimestamp) <= 1);
94+
// Allow a mismatch of 10ms
95+
assertTrue(Math.abs(currentTime - snowflakeTimestamp) <= 10);
9696
}
9797
}

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ plugins {
88
id 'maven-publish'
99
id 'com.github.johnrengelman.shadow' version '8.1.1'
1010
id 'application'
11-
id 'com.palantir.docker' version '0.35.0'
11+
id 'com.palantir.docker' version '0.36.0'
1212
}
1313

1414
ext {
1515
javaMainClass = "org.molgenis.emx2.RunMolgenisEmx2"
16-
javaVersion = JavaVersion.VERSION_17
16+
javaVersion = JavaVersion.VERSION_21
1717
}
1818

1919
allprojects {

ci-build-images/Dockerfile

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
# docker buildx build -t molgenis/ci-build:1.2.2 --platform linux/amd64 .
44
# docker push molgenis/ci-build:1.2.2
55

6-
FROM gradle:jdk17-jammy
6+
FROM gradle:jdk21-noble
7+
RUN useradd -m molgenis
78

8-
RUN apt-get update && apt-get install python3 python3-venv -y
9-
RUN apt-get install python3 python3-venv python3-pip -y
10-
RUN python3 -m pip install --upgrade build twine
9+
RUN apt-get update && apt-get install vim python3 python3-venv python3-pip python3-setuptools python3-setuptools-whl -y
10+
RUN python3 -m pip config set global.break-system-packages true
1111
RUN python3 --version
1212

1313
ENV NODE_VERSION=20.11.0
1414
RUN apt install -y curl
15+
USER molgenis
1516
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
16-
ENV NVM_DIR=/root/.nvm
17+
ENV NVM_DIR=/home/molgenis/.nvm
1718
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
1819
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
1920
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
20-
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
21+
ENV PATH="/home/molgenis/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
2122
RUN node --version
2223
RUN npm --version
24+
USER root
2325

2426

2527
RUN apt update
@@ -55,3 +57,4 @@ RUN apt-get install postgresql-client -y
5557
# GemTools & FPM For debian and redhat packages
5658
RUN apt-get install ruby-dev -y
5759
RUN gem install fpm
60+
USER molgenis

docs/install.md

+40-42
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
11
# How to install and run
22

3-
You can start molgenis-emx2:
3+
MOLGENIS EMX2 can be started in multiple ways:
4+
* using Docker Compose
5+
* using Java and PostgreSQL
6+
* using Kubernetes
47

5-
* using docker compose
6-
* using java commandline + postgresql
7-
* using kubernetes
8+
## Using Docker Compose
89

9-
Details below:
10+
Prerequisites:
11+
* Docker Compose
1012

11-
## Using docker compose
12-
13-
* Install [Docker compose](https://docs.docker.com/compose/install/).
13+
Steps:
1414
* Download
1515
molgenis-emx2 <a href="https://raw.githubusercontent.com/mswertz/molgenis-emx2/master/docker-compose.yml" download>
1616
docker-compose.yml</a> file
17-
* In directory with docker-compose.yml run:
17+
* In the directory containing the docker-compose.yml file run:
1818

19-
```
20-
docker-compose up
21-
```
19+
`docker-compose up`
2220

23-
To update to latest release, run:
21+
* To update to the latest release, run:
2422

25-
```console
26-
docker-compose pull
27-
```
23+
`docker-compose pull`
2824

29-
Stop by typing ctrl+c.
3025

31-
N.B.
26+
Stop the execution of the process by pressing CTRL+C.
3227

33-
* because postgres starts slow, emx2 will restart 2-4 times because of 'ConnectException: Connection refused'. This is
34-
normal.
35-
* the data of postgresql will be stored in 'psql_data' folder. Remove this folder you want a clean start.
36-
* if you want
37-
particular [molgenis-emx2 version](https://hub.docker.com/repository/registry-1.docker.io/mswertz/emx2/tags?page=1)
38-
then add version in docker-compose.yml file 'molgenis/molgenis-emx2:version'
28+
Note:
29+
* because PostgreSQL starts slowly EMX2 will restart 2-4 times because of 'ConnectException: Connection refused'. This is
30+
expected behaviour.
31+
* the data of the PostgreSQL database will be stored in 'psql_data' folder. Remove this folder you want a clean start.
32+
* if you want to use a specific [molgenis-emx2 version](https://hub.docker.com/repository/registry-1.docker.io/mswertz/emx2/tags?page=1)
33+
add the version number in the docker-compose.yml file with the key `molgenis/molgenis-emx2:version`
3934

40-
## Using java and your own postgresql
35+
## Using Java and your local PostgreSQL database
4136

42-
* Install java (we use java 17)
43-
* Download a molgenis-emx2-version-all.jar from [releases](https://github.com/molgenis/molgenis-emx2/releases).
44-
* Download and install [Postgresql](https://www.postgresql.org/download/) (we use 13)
45-
* Create postgresql database with name 'molgenis' and with superadmin user/pass 'molgenis'. On Linux/Mac commandline:
37+
Prerequisites:
38+
* Java version 21
39+
* PostgreSQL version 15
40+
41+
Steps:
42+
* Download a molgenis-emx2-version-all.jar file from [releases](https://github.com/molgenis/molgenis-emx2/releases).
43+
* Create a PostgreSQL database with name 'molgenis' and with superadmin username/password combination 'molgenis'.
4644
```console
4745
sudo -u postgres psql
4846
postgres=# create database molgenis;
4947
postgres=# create user molgenis with superuser encrypted password 'molgenis';
5048
postgres=# grant all privileges on database molgenis to molgenis;
5149
```
52-
* Start molgenis-emx2; will run on 8080
53-
```console
54-
java -jar molgenis-emx2-<version>-all.jar
55-
```
50+
* Start molgenis-emx2
51+
52+
`java -jar molgenis-emx2-<version>-all.jar`
5653

57-
Optionally, you can change defaults using either java properties or using env variables:
54+
The process will run on HTTP port 8080.
5855

59-
* MOLGENIS_POSTGRES_URI
60-
* MOLGENIS_POSTGRES_USER
61-
* MOLGENIS_POSTGRES_PASS
62-
* MOLGENIS_HTTP_PORT
63-
* MOLGENIS_ADMIN_PW
56+
Optionally, the following default values can be modified using either Java properties or using environment variables:
57+
* `MOLGENIS_POSTGRES_URI`
58+
* `MOLGENIS_POSTGRES_USER`
59+
* `MOLGENIS_POSTGRES_PASS`
60+
* `MOLGENIS_HTTP_PORT`
61+
* `MOLGENIS_ADMIN_PW`
6462

6563
For example:
6664

@@ -72,7 +70,7 @@ java -DMOLGENIS_POSTGRES_URI=jdbc:postgresql:mydatabase -DMOLGENIS_HTTP_PORT=909
7270

7371
If you have Kubernetes server then you can install using [Helm](https://helm.sh/docs/).
7472

75-
Add helm chart repository (once)
73+
Add Helm chart repository (once)
7674

7775
```console
7876
helm repo add emx2 https://github.com/molgenis/molgenis-ops-helm/tree/master/charts/molgenis-emx2
@@ -84,10 +82,10 @@ Run the latest release (see [Helm docs](https://helm.sh/docs/intro/using_helm/))
8482
helm install emx2/emx2
8583
```
8684

87-
Update helm repository to get newest release
85+
Refresh the Helm repository to get the latest release
8886

8987
```console
9088
helm repo update
9189
```
9290

93-
Alternatively, [download latest helm chart](https://github.com/mswertz/molgenis-emx2/tree/master/docs/helm-charts)
91+
Alternatively, [download the latest version of Helm Chart](https://github.com/mswertz/molgenis-emx2/tree/master/docs/helm-charts)

docs/molgenis/run_java.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Steps:
1313
create user molgenis with login nosuperuser inherit createrole encrypted password 'molgenis';
1414
grant all privileges on database molgenis to molgenis;
1515
```
16-
* Install java (we use adopt [OpenJDK 17](https://adoptium.net/))
16+
* Install java (we use adopt [OpenJDK 21](https://adoptium.net/))
1717
* Optionally, if you want to use [scripts](use_scripts_jobs.md) then also install python3
1818
* Download molgenis-emx2-version-all.jar from [releases](https://github.com/molgenis/molgenis-emx2/releases).
1919
* Start molgenis-emx2 using command below (will run on 8080)

docs/molgenis/run_systemd.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ We support Redhat and Ubuntu based installations.
55

66
## Java
77

8-
MOLGENIS EMX2 runs on java > 17
8+
MOLGENIS EMX2 runs on java > 21
99
<!-- tabs:start -->
1010

1111
#### **Ubuntu (apt)**

0 commit comments

Comments
 (0)