Skip to content

Commit c2dc1bb

Browse files
authored
Merge pull request #22 from OpenLiberty/staging
Merge staging to prod - Optimize image size (#21)
2 parents 75e20c9 + 6e8378a commit c2dc1bb

File tree

33 files changed

+441
-191
lines changed

33 files changed

+441
-191
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,60 @@
22

33
Anyone can contribute to the Open Liberty guides and we welcome your contributions!
44

5-
There are multiple ways to contribute: report bugs, fix bugs, contribute code, improve upon documentation, etc.
5+
There are multiple ways to contribute: report bugs, fix bugs, contribute code, improve upon documentation, etc.
66

77
## Raising issues
88

99
Please raise any bug reports in this [guide repository](../../issues). For new topics, large updates to existing guides, or general suggestions and ideas, report your issue in the [Open Liberty common guides repository](https://github.com/OpenLiberty/guides-common/issues). Be sure to search the list of open issues to see if your issue has already been raised.
1010

1111
A good bug report makes it easy for everyone to understand what you were trying to do and what went wrong. Provide as much context as possible so we can try to recreate the issue.
1212

13-
## Contributions
13+
## Contributions
1414

15-
Contributing to an Open Liberty guide is simple. All you need to do is create your own branch to include your contribution and open a pull request to the `qa` (quality assurance) branch.
15+
Contributing to an Open Liberty guide is simple. All you need to do is create your branch to include your contribution and open a pull request to the `staging` (quality assurance) branch.
1616

1717
### Text or content contributions
1818

1919
If you are contributing text or content changes via a pull request, you need to certify that the originality of the work follows the [Developer Certificate of Origin (DCO)](https://developercertificate.org).
2020

2121
Add a line to the end of the Git commit message to sign your work:
2222

23-
```
23+
```text
2424
Signed-off-by: Jane Williams <jane.williams@gmail.com>
2525
```
2626

2727
The sign-off is just a line at the end of the commit message that certifies that you wrote it or otherwise have the right to pass it on as an open source patch.
2828

29-
Use your real name when you sign. We can't accept pseudonyms or anonymous contributions.
29+
Use your real name when you sign. We can't accept pseudonyms or anonymous contributions.
3030

3131
Many Git UI tools have support for adding the `Signed-off-by` line to the end of your commit message. This line can be automatically added by the `git commit` command by using the `-s` option.
3232

33-
If reviewers agree with your change, your change will be merged to the `master` branch for publishing.
33+
If reviewers agree with your change, your change will be merged to the `prod` branch for publishing.
3434

3535
### Code contributions
3636

3737
If you are contributing trivial code changes such as typos, redundant spaces, or minor formatting and spelling errors, follow the instructions under [Text or content contributions](./CONTRIBUTING.md#text-or-content-contributions).
3838

39-
If you are contributing code changes via a pull request for non-trivial changes, you must sign off on the [Individual Contributor License Agreement](https://github.com/OpenLiberty/open-liberty/blob/master/cla/open-liberty-cla-individual.pdf). An example of a non-trivial change could be adding a new
40-
microservice to the backend application of the guide.
39+
If you are contributing code changes via a pull request for non-trivial changes, you must sign off on the [Individual Contributor License Agreement](https://github.com/OpenLiberty/open-liberty/blob/release/cla/open-liberty-cla-individual.pdf). An example of a non-trivial change could be adding a new
40+
microservice to the backend application of the guide.
4141

42-
If you are contributing changes as part of your job, you may also wish to have your employer sign a [Corporate Contributor License Agreement](https://github.com/OpenLiberty/open-liberty/blob/master/cla/open-liberty-cla-corporate.pdf).
42+
If you are contributing changes as part of your job, you may also wish to have your employer sign a [Corporate Contributor License Agreement](https://github.com/OpenLiberty/open-liberty/blob/release/cla/open-liberty-cla-corporate.pdf).
4343

44-
Instructions for how to sign and submit these agreements are located at the top of each document.
44+
Instructions for how to sign and submit these agreements are located at the top of each document.
4545

46-
After we obtain the signed CLA, you are welcome to open a pull request against the `qa` branch, and the team will be notified for review. We ask you follow these steps through the submission process:
46+
After we obtain the signed CLA, you are welcome to open a pull request against the `staging` branch, and the team will be notified for review. We ask you to follow these steps through the submission process:
4747

48-
1. Open a pull request against the `qa` branch.
48+
1. Open a pull request against the `staging` branch.
4949
2. A "CLA signed" label will be manually added by the team.
50-
3. The team will be notified and will review your change(s).
51-
- If there are further changes to be made, the team will request changes on the pull request.
50+
3. The team will be notified and will review your change(s).
51+
- If there are further changes to be made, the team will request changes on the pull request.
5252
- If the team does not agree with the change, the PR will be closed with an explanation and suggestion for follow-up.
5353
4. If the team approves, a full Open Liberty site build will be run.
5454
5. Based on the results of the build:
55-
- If further review is needed, we will let you know about a pending review from our team and discuss any necessary improvements that need to be made to your change(s).
55+
- If further review is needed, we will let you know about a pending review from our team and discuss any necessary improvements that need to be made to your change(s).
5656
- If everything is successful, the team will merge your PR.
5757

5858
## Questions and concerns
5959

6060
If you have any questions or concerns about the guides or about Open Liberty, you can visit [Gitter for Open Liberty](https://gitter.im/OpenLiberty/) and post your questions in the relevant rooms. You can also join the Open Liberty group on [Groups.io](https://groups.io/g/openliberty) to discuss any issues you have.
61+

README.adoc

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ You can find all official images on the Open Liberty https://github.com/OpenLibe
217217
inventory/Containerfile
218218
[source, Text, linenums, indent=0, role="code_column"]
219219
----
220-
include::finish/inventory/Containerfile[]
220+
include::finish/inventory/Containerfile-full[]
221221
----
222222

223223
The [hotspot=from file=0]`FROM` instruction initializes a new build stage, which indicates the parent image of the built image. If you don't need a parent image, then you can use `FROM scratch`, which makes your image a base image.
@@ -246,7 +246,7 @@ The `Containerfile` file for the `system` service follows the same instructions
246246
system/Containerfile
247247
[source, Text, linenums, indent=0, role="code_column"]
248248
----
249-
include::finish/system/Containerfile[]
249+
include::finish/system/Containerfile-full[]
250250
----
251251

252252

@@ -494,6 +494,128 @@ You can externalize the configuration of more than just the port numbers.
494494
To learn more about Open Liberty server configuration, check out the
495495
https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html[Server Configuration Overview^] docs.
496496

497+
== Optimizing the image size
498+
499+
As mentioned previously, the parent image that is used in each `Containerfile` contains the `full` tag, which includes all of the Liberty features. This parent image with the `full` tag is recommended for development, but while deploying to production it is recommended to use a parent image with the `kernel-slim` tag. The `kernel-slim` tag provides a bare minimum server with the ability to add the features required by the application.
500+
501+
[role="code_command hotspot file=0", subs="quotes"]
502+
----
503+
#Replace the `Containerfile` for the inventory service.#
504+
`inventory/Containerfile`
505+
----
506+
507+
inventory/Containerfile
508+
[source, Text, linenums, indent=0, role="code_column"]
509+
----
510+
include::finish/inventory/Containerfile[]
511+
----
512+
513+
Replace the parent image with [hotspot=kernel-slim file=0]`icr.io/appcafe/open-liberty:kernel-slim-java11-openj9-ubi` at the top of your `Containerfile`. This image contains the `kernel-slim` tag that is recommended when deploying to production.
514+
515+
Place [hotspot=features file=0]`RUN features.sh` command after the COPY command that the configuration file is copied to the `/config/` destination directory. The `features.sh` script adds the Liberty features that your application is required to operate.
516+
517+
Ensure that you repeat these instructions for the `system` service.
518+
519+
[role="code_command hotspot file=1", subs="quotes"]
520+
----
521+
#Replace the `Containerfile` for the system service.#
522+
`system/Containerfile`
523+
----
524+
525+
system/Containerfile
526+
[source, Text, linenums, indent=0, role="code_column"]
527+
----
528+
include::finish/system/Containerfile[]
529+
----
530+
531+
Continue by running the following commands to stop and remove your current containers that are using the `full` parent image:
532+
533+
[role='command']
534+
```
535+
podman stop inventory system
536+
podman rm inventory system
537+
```
538+
539+
Next, build your new images with the `kernel-slim` parent image:
540+
541+
[role='command']
542+
```
543+
podman build -t system:1.0-SNAPSHOT system/.
544+
podman build -t inventory:1.0-SNAPSHOT inventory/.
545+
```
546+
547+
Verify that the images have been built by executing the following command to list all the local images:
548+
549+
[role='command']
550+
```
551+
podman images
552+
```
553+
554+
Notice that the images for the `inventory` and `system` services now have a reduced image size.
555+
----
556+
REPOSITORY TAG IMAGE ID CREATED SIZE
557+
localhost/inventory 1.0-SNAPSHOT eee0d13f0e80 3 minutes ago 674 MB
558+
localhost/system 1.0-SNAPSHOT 5b8f87d6f0d5 4 minutes ago 726 MB
559+
----
560+
561+
After confirming that the images have been built, run the following commands to start the containers:
562+
563+
[role='command']
564+
```
565+
podman run -d --name system -p 9080:9080 system:1.0-SNAPSHOT
566+
podman run -d --name inventory -p 9081:9081 inventory:1.0-SNAPSHOT
567+
```
568+
569+
Once your containers are running, run the following command to see the list of the required features installed by `features.sh`:
570+
[role='command']
571+
```
572+
podman exec -it inventory /opt/ol/wlp/bin/productInfo featureInfo
573+
```
574+
575+
Your list of Liberty features should be similar to the following:
576+
----
577+
jndi-1.0
578+
servlet-5.0
579+
cdi-3.0
580+
concurrent-2.0
581+
jsonb-2.0
582+
jsonp-2.0
583+
mpConfig-3.0
584+
restfulWS-3.0
585+
restfulWSClient-3.0
586+
----
587+
588+
// static guide instructions:
589+
ifndef::cloud-hosted[]
590+
To ensure that your containers are working properly, try accessing the `system` service to show the system properties of the running JVM.
591+
See http://localhost:9080/system/properties[http://localhost:9080/system/properties]
592+
593+
Next, replace `[system-ip-address]` with the IP address that you obtained earlier and add your localhost system properties to the `inventory` service by visiting:
594+
`\http://localhost:9081/inventory/systems/pass:c[[system-ip-address]]`
595+
596+
Then, verify the addition of your localhost system properties to your `inventory` service.
597+
See http://localhost:9081/inventory/systems[http://localhost:9081/inventory/systems]
598+
endif::[]
599+
600+
// cloud-hosted guide instructions:
601+
ifdef::cloud-hosted[]
602+
The **system** service which shows the system properties of the running JVM, is now available to be accessed at **http://localhost:9080/system/properties**. Run the following curl command:
603+
```bash
604+
curl -s http://localhost:9080/system/properties | jq
605+
```
606+
607+
Next, you can add your local system properties at the **http://localhost:9081/inventory/systems/[system-ip-address]** URL by replacing **[system-ip-address]** with the IP address that you obtained in the previous section. Run the following commands:
608+
```bash
609+
SYSTEM_IP=`podmandocker inspect -f "{{.NetworkSettings.IPAddress }}" system`
610+
curl -s http://localhost:9081/inventory/systems/{$SYSTEM_IP} | jq
611+
```
612+
613+
Then, verify the addition of your localhost system properties to the **inventory** service at **http://localhost:9081/inventory/systems**. Run the following curl command:
614+
```bash
615+
curl -s http://localhost:9081/inventory/systems | jq
616+
```
617+
endif::[]
618+
497619
== Testing the microservices
498620

499621
You can test your microservices manually by hitting the endpoints or with automated tests that check your running containers.
@@ -538,7 +660,7 @@ Run the Maven `package` goal to compile the test classes. Run the Maven `failsaf
538660
[role='command']
539661
```
540662
mvn package
541-
mvn failsafe:integration-test -Dsystem.ip=[system-ip-address] -Dinventory.http.port=9091 -Dsystem.http.port=9080
663+
mvn failsafe:integration-test -Dsystem.ip=[system-ip-address] -Dinventory.http.port=9081 -Dsystem.http.port=9080
542664
```
543665
endif::[]
544666

@@ -549,7 +671,7 @@ Run the Maven **package** goal to compile the test classes. Run the Maven **fail
549671
```
550672
SYSTEM_IP=`podman inspect -f "{{.NetworkSettings.IPAddress }}" system`
551673
mvn package
552-
mvn failsafe:integration-test -Dsystem.ip="$SYSTEM_IP" -Dinventory.http.port=9091 -Dsystem.http.port=9080
674+
mvn failsafe:integration-test -Dsystem.ip="$SYSTEM_IP" -Dinventory.http.port=9081 -Dsystem.http.port=9080
553675
```
554676
{: codeblock}
555677
endif::[]

finish/inventory/Containerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# tag::from[]
2-
FROM icr.io/appcafe/open-liberty:full-java11-openj9-ubi
3-
# end::from[]
1+
# tag::kernel-slim[]
2+
FROM icr.io/appcafe/open-liberty:kernel-slim-java11-openj9-ubi
3+
# end::kernel-slim[]
44

55
ARG VERSION=1.0
66
ARG REVISION=SNAPSHOT
@@ -32,6 +32,10 @@ COPY --chown=1001:0 \
3232
# end::config[]
3333
# end::copy-config[]
3434

35+
# tag::features[]
36+
RUN features.sh
37+
# end::features[]
38+
3539
# tag::copy-war[]
3640
# tag::war-userID[]
3741
COPY --chown=1001:0 \
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# tag::from[]
2+
FROM icr.io/appcafe/open-liberty:full-java11-openj9-ubi
3+
# end::from[]
4+
5+
ARG VERSION=1.0
6+
ARG REVISION=SNAPSHOT
7+
8+
# tag::label[]
9+
LABEL \
10+
org.opencontainers.image.authors="Your Name" \
11+
org.opencontainers.image.vendor="Open Liberty" \
12+
org.opencontainers.image.url="local" \
13+
org.opencontainers.image.source="https://github.com/OpenLiberty/guide-containerize" \
14+
org.opencontainers.image.version="$VERSION" \
15+
org.opencontainers.image.revision="$REVISION" \
16+
vendor="Open Liberty" \
17+
name="inventory" \
18+
version="$VERSION-$REVISION" \
19+
summary="The inventory microservice from the Containerizing microservices guide" \
20+
description="This image contains the inventory microservice running with the Open Liberty runtime."
21+
# end::label[]
22+
23+
# tag::copy-config[]
24+
# tag::config-userID[]
25+
COPY --chown=1001:0 \
26+
# end::config-userID[]
27+
# tag::inventory-config[]
28+
src/main/liberty/config \
29+
# end::inventory-config[]
30+
# tag::config[]
31+
/config/
32+
# end::config[]
33+
# end::copy-config[]
34+
35+
# tag::copy-war[]
36+
# tag::war-userID[]
37+
COPY --chown=1001:0 \
38+
# end::war-userID[]
39+
# tag::inventory-war[]
40+
target/inventory.war \
41+
# end::inventory-war[]
42+
# tag::config-apps[]
43+
/config/apps
44+
# end::config-apps[]
45+
# end::copy-war[]
46+
47+
# tag::configure-sh[]
48+
RUN configure.sh
49+
# end::configure-sh[]

finish/inventory/pom.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
<dependency>
3030
<groupId>jakarta.platform</groupId>
3131
<artifactId>jakarta.jakartaee-api</artifactId>
32-
<version>8.0.0</version>
32+
<version>9.1.0</version>
3333
<scope>provided</scope>
3434
</dependency>
3535
<dependency>
3636
<groupId>org.eclipse.microprofile</groupId>
3737
<artifactId>microprofile</artifactId>
38-
<version>4.1</version>
38+
<version>5.0</version>
3939
<type>pom</type>
4040
<scope>provided</scope>
4141
</dependency>
@@ -49,25 +49,25 @@
4949
<dependency>
5050
<groupId>org.junit.jupiter</groupId>
5151
<artifactId>junit-jupiter-engine</artifactId>
52-
<version>5.7.1</version>
52+
<version>5.8.2</version>
5353
<scope>test</scope>
5454
</dependency>
5555
<dependency>
56-
<groupId>org.apache.cxf</groupId>
57-
<artifactId>cxf-rt-rs-client</artifactId>
58-
<version>3.4.3</version>
56+
<groupId>org.jboss.resteasy</groupId>
57+
<artifactId>resteasy-client</artifactId>
58+
<version>6.0.0.Final</version>
5959
<scope>test</scope>
6060
</dependency>
6161
<dependency>
62-
<groupId>org.apache.cxf</groupId>
63-
<artifactId>cxf-rt-rs-extension-providers</artifactId>
64-
<version>3.4.3</version>
62+
<groupId>org.jboss.resteasy</groupId>
63+
<artifactId>resteasy-json-binding-provider</artifactId>
64+
<version>6.0.0.Final</version>
6565
<scope>test</scope>
6666
</dependency>
6767
<dependency>
6868
<groupId>org.glassfish</groupId>
69-
<artifactId>javax.json</artifactId>
70-
<version>1.1.4</version>
69+
<artifactId>jakarta.json</artifactId>
70+
<version>2.0.1</version>
7171
<scope>test</scope>
7272
</dependency>
7373
</dependencies>
@@ -106,4 +106,4 @@
106106
</plugin>
107107
</plugins>
108108
</build>
109-
</project>
109+
</project>

finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// tag::copyright[]
22
/*******************************************************************************
3-
* Copyright (c) 2017 IBM Corporation and others.
3+
* Copyright (c) 2017, 2022 IBM Corporation and others.
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v1.0
66
* which accompanies this distribution, and is available at
@@ -9,12 +9,12 @@
99
* Contributors:
1010
* IBM Corporation - Initial implementation
1111
*******************************************************************************/
12-
// end::copyright[]
12+
// end::copyright[]
1313
package io.openliberty.guides.inventory;
1414

1515
// JAX-RS
16-
import javax.ws.rs.ApplicationPath;
17-
import javax.ws.rs.core.Application;
16+
import jakarta.ws.rs.ApplicationPath;
17+
import jakarta.ws.rs.core.Application;
1818

1919
@ApplicationPath("inventory")
2020
public class InventoryApplication extends Application {

0 commit comments

Comments
 (0)