Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added docker-compose environment for quick deployments #2320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/target/
/src/main/webapp/WEB-INF/glassfish-resources.xml
/faces-config.NavData
.data
26 changes: 26 additions & 0 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM maven:3.9.6-eclipse-temurin-11 as builder

COPY . /tmp

RUN cd /tmp && mvn package

FROM alpine:3.19.0 as dependencies

ENV MYSQL_DRIVER_VERSION=mysql-connector-j-8.2.0

RUN apk update && apk add curl unzip
WORKDIR /tmp/mysql
RUN curl --location --output "${MYSQL_DRIVER_VERSION}.zip" "https://dev.mysql.com/get/Downloads/Connector-J/${MYSQL_DRIVER_VERSION}.zip"
RUN unzip "${MYSQL_DRIVER_VERSION}.zip" && cp ${MYSQL_DRIVER_VERSION}/*.jar .

FROM payara/server-full:5.2020.3-jdk11

ENV GLASSFISH_HOME=/opt/payara/appserver
ENV PREBOOT_COMMANDS=/opt/custom/create-datasource.asadmin

COPY deployment/create-datasource.asadmin "${PREBOOT_COMMANDS}"
COPY --from=dependencies /tmp/mysql/*.jar "${GLASSFISH_HOME}/glassfish/lib/"
COPY --from=builder /tmp/target/*.war "${GLASSFISH_HOME}/../deployments/hmis.war"

EXPOSE 8080/tcp
EXPOSE 4848/tcp
27 changes: 27 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Sample deployment using containers
This folder is a sample on how to quickly spin-up (or deploy) the HMIS app together with a database. By following this guide you do not have to run java, a database or a webserver locally on your computer. Everything comes out of the box and can be cleaned up quickly.

## Requirements
- docker
- internet connection
- open ports: 3306, 4848, 8080

## How to use
All commands in subchapters assume you are in the `deployment` directory.

### Starting the environment
```
docker compose up --build
```

After some time the app will be automatically deployed to the server, including the creation of connection pool and JDBC resource. You can find the app at `localhost:8080/horizon`.

### Stopping the environment
```
docker compose down
```
To remove the entire database (to start fresh) add ` --volumes; rm -r .data` to the end of the stop command.

### Other tips
- It is still possible to interact with the admin console of the payara (glassfish) webserver at `localhost:4848`. The username for the root user is `admin` and the password is `admin`.
- You can open a mysql client connection by 'stepping into' the mysql container by running `docker exec -it deployment_db_1 bash` and once you are inside the mysql container run `mysql -ppassword` ('password' is the password here). You can also use any other sql tool and connect to localhost:3306.
3 changes: 3 additions & 0 deletions deployment/create-datasource.asadmin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking on this

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
create-jdbc-connection-pool --datasourceclassname=com.mysql.cj.jdbc.MysqlDataSource --restype=javax.sql.ConnectionPoolDataSource --property user=hmis:password=hmis:serverName=db:portNumber=3306:databaseName=hmis:useSSL=false dbPool
create-jdbc-resource --connectionpoolid dbPool jdbc/arogya
create-jdbc-resource --connectionpoolid dbPool jdbc/arogyaAudit
25 changes: 25 additions & 0 deletions deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
hmis:
build:
context: ../
dockerfile: deployment/Dockerfile
depends_on:
- db
ports:
- "4848:4848"
- "8080:8080"
environment: {}
db:
image: "mysql:8.2.0"
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: hmis
MYSQL_USER: hmis
MYSQL_PASSWORD: hmis
volumes:
- .data:/var/lib/mysql
ports:
- "3306:3306"
volumes:
data: