From 2f63d9932ee243a38e656805e75f8879f8a0ca35 Mon Sep 17 00:00:00 2001 From: Paul Gilber Date: Tue, 31 Oct 2023 12:14:50 +0000 Subject: [PATCH] update release drafter install command, move compose.yaml to deploy/docker-compose, create deploy/docker-compose.env to allow image overriding --- .github/release-drafter.yml | 2 +- README.md | 9 +++++---- deploy/docker-compose/.env | 6 ++++++ compose.yaml => deploy/docker-compose/compose.yaml | 14 +++++++------- 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 deploy/docker-compose/.env rename compose.yaml => deploy/docker-compose/compose.yaml (87%) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 0bb9aac..35d7302 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -41,5 +41,5 @@ template: | ## Install from the command line ```sh - docker pull ghcr.io/$OWNER/$REPOSITORY:v$RESOLVED_VERSION + DEMOAPP_BACKEND_IMAGE="ghcr.io/$OWNER/$REPOSITORY:v$RESOLVED_VERSION" docker compose --project-directory deploy/docker-compose up ``` diff --git a/README.md b/README.md index efcc7dc..52d53b7 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,12 @@ services: - "8080:8080" # Forwards container port 8080 to host port 8080. URL: http://localhost:8080/. Actuator URL: http://localhost:8080/actuator/health ``` ```sh -docker-compose up # builds application image when it doesn't exist -docker-compose up --build # rebuild application image -docker-compose down # remove containers, networks and volumes created by docker compose +# Note: by default, compose.yaml was configured to use an existing application image. Run build before docker compose or update compose.yaml and enable `build` field + +docker compose --project-directory deploy/docker-compose up +docker compose --project-directory deploy/docker-compose up --build # rebuild application image, only applicable if `build` field is enabled +docker compose --project-directory deploy/docker-compose down # remove containers, networks and volumes created by docker compose -# Note: by default, compose.yaml was configured to use an existing application image. Run build before docker-compose or update compose.yaml and enable `build` field ``` ## Testing Application Container Image with Container Structure Tests diff --git a/deploy/docker-compose/.env b/deploy/docker-compose/.env new file mode 100644 index 0000000..821d6c7 --- /dev/null +++ b/deploy/docker-compose/.env @@ -0,0 +1,6 @@ +DEMOAPP_BACKEND_IMAGE="demoapp-backend:latest" # locally built image +MYSQL_IMAGE="mysql:8.0" # https://hub.docker.com/_/mysql +MYSQL_ROOT_PASSWORD="local" +MYSQL_DATABASE="demoapp" +MYSQL_USER="user" +MYSQL_PASSWORD="password" \ No newline at end of file diff --git a/compose.yaml b/deploy/docker-compose/compose.yaml similarity index 87% rename from compose.yaml rename to deploy/docker-compose/compose.yaml index a0c99e9..d4ac705 100644 --- a/compose.yaml +++ b/deploy/docker-compose/compose.yaml @@ -2,15 +2,15 @@ # Service top-level element reference: https://docs.docker.com/compose/compose-file/05-services/ services: mysql: # Service name is also used as hostname when connecting from other containers - image: mysql:8.0 # https://hub.docker.com/_/mysql + image: ${MYSQL_IMAGE} # use image specified in .env file # Docker Hub mysql image already exposes port 3306, thus `expose` keyword can be omitted # expose: # - "3306" environment: - MYSQL_ROOT_PASSWORD: local - MYSQL_DATABASE: demoapp - MYSQL_USER: user - MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} healthcheck: # Login to mysql demoapp db test: mysql --host=localhost --user=root --password=$$MYSQL_ROOT_PASSWORD demoapp # command for testing health @@ -31,7 +31,7 @@ services: depends_on: mysql: condition: service_healthy # healthy status is indicated by `healthcheck` keyword - image: demoapp-backend:latest # use built image + image: ${DEMOAPP_BACKEND_IMAGE} # use image specified in .env file # Build image from Containerfile # build: # context: . @@ -39,7 +39,7 @@ services: environment: # Externalized Spring Configuration: https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/html/boot-features-external-config.html SPRING_DATASOURCE_USERNAME: root - SPRING_DATASOURCE_PASSWORD: local + SPRING_DATASOURCE_PASSWORD: ${MYSQL_ROOT_PASSWORD} healthcheck: # Check Spring Boot Actuator test: curl --fail http://localhost:8080/actuator/health # command for testing health