Skip to content

Commit

Permalink
Add shell scripts and documentation to build and push Docker images f…
Browse files Browse the repository at this point in the history
…or amd64 and arm64 architectures (spring-petclinic#252)
  • Loading branch information
arey authored Jan 5, 2024
1 parent 161c6bb commit 81a1cc0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ You can tell Config Server to use your local Git repository by using `native` Sp
`-Dspring.profiles.active=native -DGIT_REPO=/projects/spring-petclinic-microservices-config`

## Starting services locally with docker-compose
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.

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`
In order to start entire infrastructure using Docker, you have to build images by executing
``bash
./mvnw clean install -P buildDocker
``
This requires `Docker` or `Docker desktop` to be installed and running.

Alternatively you can also build all the images on `Podman`, which requires Podman or Podman Desktop to be installed and running.
```bash
./mvnw clean install -PbuildDocker -Dcontainer.executable=podman
```
By default, the Docker OCI image is build for an `linux/amd64` platform.
For other architectures, you could change it by using the `-Dcontainer.platform` maven command line argument.
For instance, if you target container images for an Apple M2, you could use the command line with the `linux/arm64` architecture:
```bash
./mvnw clean install -P buildDocker -Dcontainer.platform="linux/arm64"
```

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

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

## Pushing to a Docker registry

Docker images for `linux/amd64` and `linux/arm64` platforms have been published into DockerHub
in the [springcommunity](https://hub.docker.com/u/springcommunity) organization.
You can pull an image:
```bash
docker pull springcommunity/spring-petclinic-config-server
```
You may prefer to build then push images to your own Docker registry.

### Choose your Docker registry

You need to define your target Docker registry.
Make sure you're already logged in by running `docker login <endpoint>` or `docker login` if you're just targeting Docker hub.

Setup the `REPOSITORY_PREFIX` env variable to target your Docker registry.
If you're targeting Docker hub, simple provide your username, for example:
```bash
export REPOSITORY_PREFIX=springcommunity
```

For other Docker registries, provide the full URL to your repository, for example:
```bash
export REPOSITORY_PREFIX=harbor.myregistry.com/petclinic
```

To push Docker image for the `linux/amd64` and the `linux/arm64` platform to your own registry, please use the command line:
```bash
mvn clean install -Dmaven.test.skip -P buildDocker -Ddocker.image.prefix=${REPOSITORY_PREFIX} -Dcontainer.build.extraarg="--push" -Dcontainer.platform="linux/amd64,linux/arm64"
```

The `scripts/pushImages.sh` and `scripts/tagImages.sh` shell scripts could also be used once you build your image with the `buildDocker` maven profile.
The `scripts/tagImages.sh` requires to declare the `VERSION` env variable.

## Interesting Spring Petclinic forks

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


# Contributing
## Contributing

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.

Expand Down
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
<docker.image.prefix>springcommunity</docker.image.prefix>
<docker.image.exposed.port>9090</docker.image.exposed.port>
<docker.image.dockerfile.dir>${basedir}</docker.image.dockerfile.dir>
<!-- podman is also supported -->
<container.executable>docker</container.executable>
<!-- By default, the OCI image is build for the linux/amd64 platform -->
<!-- For Apple Silicon M2 Chip you have to change it to the linux/arm64 -->
<container.platform>linux/amd64</container.platform>
<!-- The -load option is a shortcut for or -output=type=docker -->
<!-- Could be changed by the -push option !-->
<container.build.extraarg>--load</container.build.extraarg>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -147,11 +154,13 @@
<argument>build</argument>
<argument>-f</argument>
<argument>Dockerfile</argument>
<argument>--load</argument>
<argument>--build-arg</argument>
<argument>ARTIFACT_NAME=${project.build.finalName}</argument>
<argument>--build-arg</argument>
<argument>EXPOSED_PORT=${docker.image.exposed.port}</argument>
<argument>--platform</argument>
<argument>${container.platform}</argument>
<argument>${container.build.extraarg}</argument>
<argument>-t</argument>
<argument>${docker.image.prefix}/${project.artifactId}</argument>
<argument>${project.build.directory}</argument>
Expand Down
8 changes: 8 additions & 0 deletions scripts/pushImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
docker push ${REPOSITORY_PREFIX}/spring-petclinic-config-server:${VERSION}
docker push ${REPOSITORY_PREFIX}/spring-petclinic-discovery-server:${VERSION}
docker push ${REPOSITORY_PREFIX}/spring-petclinic-api-gateway:${VERSION}
docker push ${REPOSITORY_PREFIX}/spring-petclinic-visits-service:${VERSION}
docker push ${REPOSITORY_PREFIX}/spring-petclinic-vets-service:${VERSION}
docker push ${REPOSITORY_PREFIX}/spring-petclinic-customers-service:${VERSION}
docker push ${REPOSITORY_PREFIX}/spring-petclinic-admin-server:${VERSION}
8 changes: 8 additions & 0 deletions scripts/tagImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-config-server ${REPOSITORY_PREFIX}/spring-petclinic-config-server:${VERSION}
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-discovery-server ${REPOSITORY_PREFIX}/spring-petclinic-discovery-server:${VERSION}
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-api-gateway ${REPOSITORY_PREFIX}/spring-petclinic-api-gateway:${VERSION}
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-visits-service ${REPOSITORY_PREFIX}/spring-petclinic-visits-service:${VERSION}
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-vets-service ${REPOSITORY_PREFIX}/spring-petclinic-vets-service:${VERSION}
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-customers-service ${REPOSITORY_PREFIX}/spring-petclinic-customers-service:${VERSION}
docker tag ${REPOSITORY_PREFIX}/spring-petclinic-admin-server ${REPOSITORY_PREFIX}/spring-petclinic-admin-server:${VERSION}

0 comments on commit 81a1cc0

Please sign in to comment.