Skip to content

Commit

Permalink
feat: place all Docker files into a single directory (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-baiborodine authored Oct 22, 2023
1 parent 98fb4c9 commit a7cc4e4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:

- name: Build image
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME:$IMAGE_TAG
docker build --file container/Dockerfile --tag $IMAGE_NAME:$IMAGE_TAG .
docker tag $IMAGE_NAME:$IMAGE_TAG $IMAGE_NAME:latest
- name: Log into registry
Expand All @@ -62,4 +62,4 @@ jobs:
- name: Push image
run: |
docker push $IMAGE_NAME:$IMAGE_TAG
docker push $IMAGE_NAME:latest
docker push $IMAGE_NAME:latest
4 changes: 2 additions & 2 deletions Dockerfile → container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM maven:3-openjdk-17 AS builder

WORKDIR /usr/src/app

COPY . .
COPY .. .

RUN mvn --batch-mode package -DskipTests -DskipITs; \
mv /usr/src/app/target/campsite-booking-$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout).jar \
Expand Down Expand Up @@ -39,7 +39,7 @@ RUN set -ex; \
gosu nobody true

COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /usr/src/app/target/app.jar ${APP_HOME}/app.jar
COPY docker-entrypoint.sh /usr/local/bin/
COPY container/docker-entrypoint.sh /usr/local/bin/

RUN chmod a+x /usr/local/bin/docker-entrypoint.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ services:
- "3316:3306"
- "33070:33060"
volumes:
- ../mysql/conf.d:/etc/mysql/conf.d
- ../mysql/initdb.d:/docker-entrypoint-initdb.d
- ../campsite-booking-service-mysql/mysql/conf.d:/etc/mysql/conf.d
- ../campsite-booking-service-mysql/mysql/initdb.d:/docker-entrypoint-initdb.d

api:
build: ..
campsite-booking-service:
# build from the source
build:
context: ../..
dockerfile: container/Dockerfile
# or use the latest image from Docker Hub
# image: ibaiborodine/campsite-booking:latest
depends_on:
- db
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions container/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'

services:
campsite-booking-service:
# build from the source
build:
context: ..
dockerfile: container/Dockerfile
# or use the latest image from Docker Hub
# image: ibaiborodine/campsite-booking:latest
environment:
- SPRING_PROFILES_ACTIVE=in-memory-db
ports:
- "80:8080"
File renamed without changes.
10 changes: 0 additions & 10 deletions docker-compose.yml

This file was deleted.

32 changes: 19 additions & 13 deletions readme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,35 @@ The Swagger UI is available at `http://localhost:8080/swagger-ui.html`.
```bash
$ git clone https://github.com/igor-baiborodine/campsite-booking.git
$ cd campsite-booking
$ docker build --rm -t campsite-booking .
$ docker run -e "SPRING_PROFILES_ACTIVE=in-memory-db" --name campsite-booking -d campsite-booking
$ docker logs -f campsite-booking
$ docker build --rm --file container/Dockerfile --tag campsite-booking-service .
$ docker run -e "SPRING_PROFILES_ACTIVE=in-memory-db" --name campsite-booking-service -d campsite-booking-service
$ docker logs -f campsite-booking-service
```
The Swagger UI is available at `http://container-ip:8080/swagger-ui.html`. To get the container IP address, execute the following command:

The Swagger UI is available at `http://<container-ip>:8080/swagger-ui.html`. To get the container IP
address, execute the following command:

```console
$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' campsite-booking
$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' campsite-booking-service
```

Via the host machine on port 80:
```console
$ docker run -e "SPRING_PROFILES_ACTIVE=in-memory-db" --name campsite-booking -p 80:8080 -d campsite-booking
$ docker run -e "SPRING_PROFILES_ACTIVE=in-memory-db" --name campsite-booking-service -p 80:8080 -d campsite-booking-service
```
The Swagger UI is available at `http://localhost:80/swagger-ui.html` or `http://host-ip:80/swagger-ui.html`.

... or with an [image from Docker Hub](https://hub.docker.com/r/ibaiborodine/campsite-booking):
```console
$ docker run -e "SPRING_PROFILES_ACTIVE=in-memory-db" --name campsite-booking -p 80:8080 -d ibaiborodine/campsite-booking
$ docker run -e "SPRING_PROFILES_ACTIVE=in-memory-db" --name campsite-booking-service -p 80:8080 -d ibaiborodine/campsite-booking-service
```
... or with in-memory DB [docker-compose](../docker-compose.yml):
... or with in-memory DB [docker-compose](../container/docker-compose.yml):
```console
$ docker-compose up -d
$ docker compose -f container/docker-compose.yml up -d
```
... or with MySQL [docker-compose](../mysql/docker-compose.yml):
... or with MySQL [docker-compose](../container/campsite-booking-service-mysql/docker-compose.yml):
```console
$ mysql/docker-compose up -d
$ docker compose -f container/campsite-booking-service-mysql/docker-compose.yml up -d
```

## Tests
Expand Down Expand Up @@ -150,8 +154,10 @@ If the operation is successful, you will get the following response:

### Concurrent Tests

Start an instance of the Campsite Booking API via Docker Compose either in [the in-memory-db](../docker-compose.yml) or
in [mysql](../mysql/docker-compose.yml) profile.
Start an instance of the Campsite Booking API via Docker Compose either
in [the in-memory-db](../container/docker-compose.yml) or
in [mysql](../container/campsite-booking-service-mysql/docker-compose.yml) profile.

```bash
$ docker-compose.yml up -d
```
Expand Down

0 comments on commit a7cc4e4

Please sign in to comment.