Skip to content

Commit d5495ab

Browse files
authored
build: docker multistage builds (#320)
* build: docker multistage builds allow repeatable builds without a need to install java/maven locally Signed-off-by: Andrew Berezovskyi <[email protected]> * fix: parent POM Signed-off-by: Andrew Berezovskyi <[email protected]> * fix: test compose config Signed-off-by: Andrew Berezovskyi <[email protected]> * fix: paths Signed-off-by: Andrew Berezovskyi <[email protected]> --------- Signed-off-by: Andrew Berezovskyi <[email protected]>
1 parent 7d39f96 commit d5495ab

27 files changed

+412
-373
lines changed

README.md

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,17 @@ After following these steps, proceed to the steps listed in the next section _Na
5858

5959
If you wish to run 4 OSLC servers as 4 containers similar to how one would deploy them in the cloud, you could follow steps listed in this subsection. Prerequisites:
6060

61-
- JDK 17
62-
- Maven 3
61+
- JDK 17 (only for non-Docker builds)
62+
- Maven 3.9 (only for non-Docker builds)
6363
- Docker CE 19 or equivalent
64-
- (Optional) Docker Compose
64+
- Docker Compose v2
6565

6666
Docker Compose setup was also tested with Rancher Desktop 1.0.1.
6767

6868
```
6969
cd src/
70-
mvn clean install
71-
7270
# Using Docker Compose
7371
docker compose up --build
74-
75-
# or, only using Docker
76-
cd server-rm/
77-
mvn clean package
78-
docker build -t refimpl-server-rm .
79-
docker run -d --name=oslc-refimpl-rm --rm -p 8800:8080 refimpl-server-rm
80-
81-
cd ../server-cm/
82-
mvn clean package
83-
docker build -t refimpl-server-cm .
84-
docker run -d --name=oslc-refimpl-cm --rm -p 8801:8080 refimpl-server-cm
85-
86-
cd ../server-qm/
87-
mvn clean package
88-
docker build -t refimpl-server-qm .
89-
docker run -d --name=oslc-refimpl-qm --rm -p 8802:8080 refimpl-server-qm
90-
91-
cd ../server-am/
92-
mvn clean package
93-
docker build -t refimpl-server-am .
94-
docker run -d --name=oslc-refimpl-am --rm -p 8803:8080 refimpl-server-am
95-
cd ..
9672
```
9773

9874
Make sure all is up and running:
@@ -112,23 +88,12 @@ To see logs:
11288

11389
docker logs oslc-refimpl-am -f
11490

115-
To stop:
116-
117-
docker stop oslc-refimpl-am
118-
docker stop oslc-refimpl-cm
119-
docker stop oslc-refimpl-rm
120-
docker stop oslc-refimpl-qm
12191

12292
### Running on Tomcat in Docker
12393

12494
```bash
12595
cd src/
126-
mvn clean install
127-
128-
cd server-rm/
129-
mvn clean package -Pwith-jstl-impl
130-
docker build -f tomcat.Dockerfile -t refimpl-server-rm .
131-
docker run -p 8800:8080 refimpl-server-rm
96+
docker compose -f docker-compose.tomcat.yml up --build
13297
```
13398

13499
### Running on Tomcat via Maven

model/representations.aird

Lines changed: 245 additions & 269 deletions
Large diffs are not rendered by default.

src/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
overlays/
2+
target/
3+
*/target/

src/client-toolchain/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<parent>
4-
<artifactId>parent</artifactId>
54
<groupId>co.oslc.refimpl</groupId>
6-
<version>0.0.1-SNAPSHOT</version>
5+
<artifactId>parent</artifactId>
6+
<version>0.3.0-SNAPSHOT</version>
7+
<relativePath>../pom.xml</relativePath>
78
</parent>
89
<modelVersion>4.0.0</modelVersion>
910

src/docker-compose.tomcat.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
version: "3.9"
21
services:
32
server-rm:
43
build:
5-
context: server-rm/
6-
dockerfile: tomcat.Dockerfile
4+
context: ./
5+
dockerfile: ./server-rm/tomcat.Dockerfile
76
ports:
87
- "8800:8080"
98
server-cm:
109
build:
11-
context: server-cm/
12-
dockerfile: tomcat.Dockerfile
10+
context: ./
11+
dockerfile: ./server-cm/tomcat.Dockerfile
1312
ports:
1413
- "8801:8080"
1514
server-qm:
1615
build:
17-
context: server-qm/
18-
dockerfile: tomcat.Dockerfile
16+
context: ./
17+
dockerfile: ./server-qm/tomcat.Dockerfile
1918
ports:
2019
- "8802:8080"
2120
server-am:
2221
build:
23-
context: server-am/
24-
dockerfile: tomcat.Dockerfile
22+
context: ./
23+
dockerfile: ./server-am/tomcat.Dockerfile
2524
ports:
2625
- "8803:8080"

src/docker-compose.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
version: "3.9"
21
services:
32
server-rm:
4-
build: server-rm/
3+
build:
4+
context: ./
5+
dockerfile: server-rm/Dockerfile
56
ports:
6-
- "8800:8080"
7+
- "127.0.0.1:8800:8080"
78
server-cm:
8-
build: server-cm/
9+
build:
10+
context: ./
11+
dockerfile: server-cm/Dockerfile
912
ports:
10-
- "8801:8080"
13+
- "127.0.0.1:8801:8080"
1114
server-qm:
12-
build: server-qm/
15+
build:
16+
context: ./
17+
dockerfile: server-qm/Dockerfile
1318
ports:
14-
- "8802:8080"
19+
- "127.0.0.1:8802:8080"
1520
server-am:
16-
build: server-am/
21+
build:
22+
context: ./
23+
dockerfile: server-am/Dockerfile
1724
ports:
18-
- "8803:8080"
25+
- "127.0.0.1:8803:8080"

src/lib-common/pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
xmlns="http://maven.apache.org/POM/4.0.0"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5-
<!-- <parent>
5+
<parent>
66
<groupId>co.oslc.refimpl</groupId>
77
<artifactId>parent</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
9-
</parent>-->
10-
<groupId>co.oslc.refimpl</groupId>
8+
<version>0.3.0-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
1111
<artifactId>lib-common</artifactId>
12-
<version>0.0.1-SNAPSHOT</version>
1312
<name>OSLC RefImpl common library</name>
1413
<packaging>jar</packaging>
1514

src/pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<name>OSLC 2020 RefImpl (aggregator)</name>
55
<groupId>co.oslc.refimpl</groupId>
66
<artifactId>parent</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
7+
<version>0.3.0-SNAPSHOT</version>
88
<packaging>pom</packaging>
99

1010
<properties>
@@ -21,8 +21,18 @@
2121
<module>server-qm</module>
2222
<module>server-am</module>
2323
<module>client-toolchain</module>
24-
</modules>
24+
</modules>
2525

26+
<dependencyManagement>
27+
<dependencies>
28+
<dependency>
29+
<groupId>co.oslc.refimpl</groupId>
30+
<artifactId>lib-common</artifactId>
31+
<version>${project.version}</version>
32+
</dependency>
33+
</dependencies>
34+
</dependencyManagement>
35+
2636
<profiles>
2737
<profile>
2838
<id>acceptance</id>

src/refimpl-tests/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>co.oslc.refimpl</groupId>
77
<artifactId>parent</artifactId>
8-
<version>0.0.1-SNAPSHOT</version>
8+
<version>0.3.0-SNAPSHOT</version>
99
</parent>
1010
<artifactId>refimpl-tests</artifactId>
1111
<packaging>jar</packaging>
@@ -66,7 +66,12 @@
6666
</dependencyManagement>
6767

6868
<dependencies>
69-
69+
<dependency>
70+
<groupId>org.slf4j</groupId>
71+
<artifactId>slf4j-simple</artifactId>
72+
<version>2.0.16</version>
73+
<scope>test</scope>
74+
</dependency>
7075
<!-- Testcontainers -->
7176
<dependency>
7277
<groupId>commons-io</groupId>

src/refimpl-tests/src/test/groovy/OslcSpec.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ import java.time.Duration
77

88
@Testcontainers
99
class OslcSpec extends Specification {
10+
public static final int STARTUP_TIMEOUT = 120
11+
1012
public static final String RM_SVC = "server-rm"
1113
public static final String CM_SVC = "server-cm"
1214
public static final String QM_SVC = "server-qm"
1315
public static final String AM_SVC = "server-am"
1416

17+
// static final int RM_PORT = 8800
18+
// static final int CM_PORT = 8801
19+
// static final int QM_PORT = 8802
20+
// static final int AM_PORT = 8803
21+
// static private File composeFile = new File("../docker-compose.yml")
22+
1523
static final int RM_PORT = 8080
1624
static final int CM_PORT = 8080
1725
static final int QM_PORT = 8080
1826
static final int AM_PORT = 8080
19-
20-
public static final int STARTUP_TIMEOUT = 120
21-
22-
// static private File composeFile = new File("../docker-compose.yml")
2327
static private File composeFile = new File("src/test/resources/docker-compose.yml")
2428

2529
static private ComposeContainer environment =

0 commit comments

Comments
 (0)