From 02e3b6df660c80ebfd1951a25ca15f190762de3d Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Mon, 30 Sep 2024 19:17:13 -0500 Subject: [PATCH] Basic Docker and Docker Compose containerization working. --- .gitignore | 3 ++ Dockerfile | 11 +++++ README.md | 17 +++++++ compose.yaml | 56 +++++++++++++++++++++++ src/main/resources/application.properties | 14 +++--- 5 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 compose.yaml diff --git a/.gitignore b/.gitignore index c2065bc..d7d1b97 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ + +# Custom +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9171f51 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM gradle:8.8.0-jdk21 AS build +WORKDIR /mme-api +COPY . /mme-api +RUN gradle build + +FROM eclipse-temurin:21 +WORKDIR /mme-api +COPY --from=build /mme-api/build/libs/api-0.1.0-SNAPSHOT.jar . +COPY dev-data ./dev-data/ +EXPOSE 8080 +CMD ["java", "-jar", "api-0.1.0-SNAPSHOT.jar", "--spring.profiles.active=dev"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d0b7b3 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Meals Made Easy API + +## Getting Started +First, create a `.env` file with the following environment variables: + +- `MINIO_ROOT_PASSWORD=` +- `MYSQL_ROOT_PASSWORD=` +- `MYSQL_PASSWORD=` + +Then run `docker compose up -d --build`. The `--build` option can be omitted if you +have already built the `api` from `Dockerfile`. Once Docker Compose has finished +starting everything, navigate to `http://localhost:8080/greeting`. +You should see a simple "Hello, World!" greeting. + +**N.b.: the current configuration of the app is to use the `dev` Spring-Boot profile, +which seeds the app with some simple recipes whose sources are located in the +`dev-data` directory.** \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..1115d62 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,56 @@ +name: meals-made-easy-api +services: + db: + image: mysql:latest + ports: + - '55001:3306' + - '55000:33060' + env_file: .env + environment: + MYSQL_DATABASE: meals_made_easy_api + MYSQL_USER: meals-made-easy-api-user + healthcheck: + test: mysqladmin ping -u $$MYSQL_USER --password=$$MYSQL_PASSWORD + interval: 5s + timeout: 10s + retries: 10 + volumes: + - mysql-data:/var/lib/mysql + minio: + image: minio/minio:latest + ports: + - 9000:9000 + - 9001:9001 + env_file: + - .env + environment: + MINIO_ROOT_USER: minio-root + volumes: + - minio-data:/data + command: + - server + - /data + - --console-address + - :9001 + api: + build: . + depends_on: + db: + condition: service_healthy + minio: + condition: service_started + env_file: + - .env + environment: + MYSQL_HOST: db + MYSQL_PORT: 3306 + MYSQL_DATABASE: meals_made_easy_api + MYSQL_USERNAME: meals-made-easy-api-user + MINIO_HOST: minio + MINIO_PORT: 9000 + MINIO_ROOT_USER: minio-root + ports: + - 8080:8080 +volumes: + mysql-data: + minio-data: diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e809717..5d686b0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,13 +1,13 @@ spring.application.name=meals-made-easy-api spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:55001/meals_made_easy_api -spring.datasource.username=meals-made-easy-api-user -spring.datasource.password=devpass +spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:meals_made_easy_api} +spring.datasource.username=${MYSQL_USERNAME:meals-made-easy-api-user} +spring.datasource.password=${MYSQL_PASSWORD} spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver app.mealsmadeeasy.api.baseUrl=http://localhost:8080 app.mealsmadeeasy.api.security.access-token-lifetime=60 app.mealsmadeeasy.api.security.refresh-token-lifetime=3600 -app.mealsmadeeasy.api.minio.endpoint=http://localhost:9000 -app.mealsmadeeasy.api.minio.accessKey=minio-root -app.mealsmadeeasy.api.minio.secretKey=test0123 -app.mealsmadeeasy.api.images.bucketName=images \ No newline at end of file +app.mealsmadeeasy.api.minio.endpoint=http://${MINIO_HOST:localhost}:${MINIO_PORT:9000} +app.mealsmadeeasy.api.minio.accessKey=${MINIO_ROOT_USER} +app.mealsmadeeasy.api.minio.secretKey=${MINIO_ROOT_PASSWORD} +app.mealsmadeeasy.api.images.bucketName=images