Skip to content

Commit 81a1cc0

Browse files
authored
Add shell scripts and documentation to build and push Docker images for amd64 and arm64 architectures (#252)
1 parent 161c6bb commit 81a1cc0

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,22 @@ You can tell Config Server to use your local Git repository by using `native` Sp
2626
`-Dspring.profiles.active=native -DGIT_REPO=/projects/spring-petclinic-microservices-config`
2727

2828
## Starting services locally with docker-compose
29-
In order to start entire infrastructure using Docker, you have to build images by executing `./mvnw clean install -P buildDocker` . This requires Docker or Docker desktop to be installed and running.
30-
31-
Alternatively you can also build all the images on Podman, which requires Podman or Podman Desktop to be installed and running. `./mvnw clean install -PbuildDocker -Dcontainer.executable=podman`
29+
In order to start entire infrastructure using Docker, you have to build images by executing
30+
``bash
31+
./mvnw clean install -P buildDocker
32+
``
33+
This requires `Docker` or `Docker desktop` to be installed and running.
34+
35+
Alternatively you can also build all the images on `Podman`, which requires Podman or Podman Desktop to be installed and running.
36+
```bash
37+
./mvnw clean install -PbuildDocker -Dcontainer.executable=podman
38+
```
39+
By default, the Docker OCI image is build for an `linux/amd64` platform.
40+
For other architectures, you could change it by using the `-Dcontainer.platform` maven command line argument.
41+
For instance, if you target container images for an Apple M2, you could use the command line with the `linux/arm64` architecture:
42+
```bash
43+
./mvnw clean install -P buildDocker -Dcontainer.platform="linux/arm64"
44+
```
3245

3346
Once images are ready, you can start them with a single command
3447
`docker-compose up` or `podman-compose up`.
@@ -144,13 +157,46 @@ All those three REST controllers `OwnerResource`, `PetResource` and `VisitResour
144157
| Circuit Breaker | [Resilience4j fallback method](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java) |
145158
| Grafana / Prometheus Monitoring | [Micrometer implementation](https://micrometer.io/), [Spring Boot Actuator Production Ready Metrics] |
146159

147-
Front-end module | Files |
160+
| Front-end module | Files |
148161
|-------------------|-------|
149162
| Node and NPM | [The frontend-maven-plugin plugin downloads/installs Node and NPM locally then runs Bower and Gulp](spring-petclinic-ui/pom.xml) |
150163
| Bower | [JavaScript libraries are defined by the manifest file bower.json](spring-petclinic-ui/bower.json) |
151164
| Gulp | [Tasks automated by Gulp: minify CSS and JS, generate CSS from LESS, copy other static resources](spring-petclinic-ui/gulpfile.js) |
152165
| Angular JS | [app.js, controllers and templates](spring-petclinic-ui/src/scripts/) |
153166

167+
## Pushing to a Docker registry
168+
169+
Docker images for `linux/amd64` and `linux/arm64` platforms have been published into DockerHub
170+
in the [springcommunity](https://hub.docker.com/u/springcommunity) organization.
171+
You can pull an image:
172+
```bash
173+
docker pull springcommunity/spring-petclinic-config-server
174+
```
175+
You may prefer to build then push images to your own Docker registry.
176+
177+
### Choose your Docker registry
178+
179+
You need to define your target Docker registry.
180+
Make sure you're already logged in by running `docker login <endpoint>` or `docker login` if you're just targeting Docker hub.
181+
182+
Setup the `REPOSITORY_PREFIX` env variable to target your Docker registry.
183+
If you're targeting Docker hub, simple provide your username, for example:
184+
```bash
185+
export REPOSITORY_PREFIX=springcommunity
186+
```
187+
188+
For other Docker registries, provide the full URL to your repository, for example:
189+
```bash
190+
export REPOSITORY_PREFIX=harbor.myregistry.com/petclinic
191+
```
192+
193+
To push Docker image for the `linux/amd64` and the `linux/arm64` platform to your own registry, please use the command line:
194+
```bash
195+
mvn clean install -Dmaven.test.skip -P buildDocker -Ddocker.image.prefix=${REPOSITORY_PREFIX} -Dcontainer.build.extraarg="--push" -Dcontainer.platform="linux/amd64,linux/arm64"
196+
```
197+
198+
The `scripts/pushImages.sh` and `scripts/tagImages.sh` shell scripts could also be used once you build your image with the `buildDocker` maven profile.
199+
The `scripts/tagImages.sh` requires to declare the `VERSION` env variable.
154200

155201
## Interesting Spring Petclinic forks
156202

@@ -163,7 +209,7 @@ If you have a special interest in a different technology stack
163209
that could be used to implement the Pet Clinic then please join the community there.
164210

165211

166-
# Contributing
212+
## Contributing
167213

168214
The [issue tracker](https://github.com/spring-petclinic/spring-petclinic-microservices/issues) is the preferred channel for bug reports, features requests and submitting pull requests.
169215

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@
3939
<docker.image.prefix>springcommunity</docker.image.prefix>
4040
<docker.image.exposed.port>9090</docker.image.exposed.port>
4141
<docker.image.dockerfile.dir>${basedir}</docker.image.dockerfile.dir>
42+
<!-- podman is also supported -->
4243
<container.executable>docker</container.executable>
44+
<!-- By default, the OCI image is build for the linux/amd64 platform -->
45+
<!-- For Apple Silicon M2 Chip you have to change it to the linux/arm64 -->
46+
<container.platform>linux/amd64</container.platform>
47+
<!-- The -load option is a shortcut for or -output=type=docker -->
48+
<!-- Could be changed by the -push option !-->
49+
<container.build.extraarg>--load</container.build.extraarg>
4350
</properties>
4451

4552
<dependencyManagement>
@@ -147,11 +154,13 @@
147154
<argument>build</argument>
148155
<argument>-f</argument>
149156
<argument>Dockerfile</argument>
150-
<argument>--load</argument>
151157
<argument>--build-arg</argument>
152158
<argument>ARTIFACT_NAME=${project.build.finalName}</argument>
153159
<argument>--build-arg</argument>
154160
<argument>EXPOSED_PORT=${docker.image.exposed.port}</argument>
161+
<argument>--platform</argument>
162+
<argument>${container.platform}</argument>
163+
<argument>${container.build.extraarg}</argument>
155164
<argument>-t</argument>
156165
<argument>${docker.image.prefix}/${project.artifactId}</argument>
157166
<argument>${project.build.directory}</argument>

scripts/pushImages.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-config-server:${VERSION}
3+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-discovery-server:${VERSION}
4+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-api-gateway:${VERSION}
5+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-visits-service:${VERSION}
6+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-vets-service:${VERSION}
7+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-customers-service:${VERSION}
8+
docker push ${REPOSITORY_PREFIX}/spring-petclinic-admin-server:${VERSION}

scripts/tagImages.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-config-server ${REPOSITORY_PREFIX}/spring-petclinic-config-server:${VERSION}
3+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-discovery-server ${REPOSITORY_PREFIX}/spring-petclinic-discovery-server:${VERSION}
4+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-api-gateway ${REPOSITORY_PREFIX}/spring-petclinic-api-gateway:${VERSION}
5+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-visits-service ${REPOSITORY_PREFIX}/spring-petclinic-visits-service:${VERSION}
6+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-vets-service ${REPOSITORY_PREFIX}/spring-petclinic-vets-service:${VERSION}
7+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-customers-service ${REPOSITORY_PREFIX}/spring-petclinic-customers-service:${VERSION}
8+
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-admin-server ${REPOSITORY_PREFIX}/spring-petclinic-admin-server:${VERSION}

0 commit comments

Comments
 (0)