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

Docker setup for Avni Server #649

Merged
merged 3 commits into from
Nov 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ dev-commands.txt
/static/
/avni-server-api/log/
/blacklisted.json
**/*.env
14 changes: 14 additions & 0 deletions avni-server-api/src/main/resources/build_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create user :OPENCHS_DATABASE_USER with password :'OPENCHS_DATABASE_PASSWORD' createrole;
create database :OPENCHS_DATABASE with owner openchs;
\c :OPENCHS_DATABASE
create extension if not exists "uuid-ossp";
\c :OPENCHS_DATABASE
create extension if not exists "ltree";
\c :OPENCHS_DATABASE
create extension if not exists "hstore";
\c postgres
create role demo with NOINHERIT NOLOGIN;
grant demo to :OPENCHS_DATABASE_USER;
create role openchs_impl;
grant openchs_impl to :OPENCHS_DATABASE_USER;
create role organisation_user createrole admin openchs_impl;
11 changes: 11 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore all files in the root directory
*
# Include the src directory
!src/
# Include the pom.xml file
!pom.xml
# Exclude the target directory and its contents
.gradle/
.idea/
.github/
.circleci/
20 changes: 20 additions & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
OPENCHS_SERVER_PORT=8021
OPENCHS_SERVER_OPTS="-Dlogging.file=/var/log/openchs/chs.log -Dlogging.path=/var/log/openchs/ -Dlogging.file.max-size=5mb -Xmx250m -XX:ErrorFile=/var/log/openchs/jvm.log"
OPENCHS_DATABASE_HOST=db
OPENCHS_DATABASE=openchs
OPENCHS_DATABASE_USER=openchs
OPENCHS_DATABASE_PASSWORD=password
OPENCHS_DATABASE_URL="jdbc:postgresql://db:5432/openchs?currentSchema=public"
OPENCHS_USER_POOL=ap-south-1_qEHGuJJOO
OPENCHS_CLIENT_ID=34u3c6q3poij1aphqcn57363mp
OPENCHS_MODE=live
AVNI_IDP_TYPE=none
OPENCHS_SERVER_BUGSNAG_API_KEY=
OPENCHS_BUGSNAG_RELEASE_STAGE=staging
OPENCHS_BUCKET_NAME=staging-user-media
OPENCHS_IAM_USER=staging_app_iam_user
OPENCHS_IAM_USER_ACCESS_KEY=
OPENCHS_IAM_USER_SECRET_ACCESS_KEY=
OPENCHS_KEYCLOAK_CLIENT_SECRET=dsfhdfdsfh323
OPENCHS_KEYCLOAK_SERVER=https://keycloak.example.com
OPENCHS_KEYCLOAK_ENABLED=false
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#build stage using gradle
FROM gradle:5.6 AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle clean build --no-daemon -x test

#deploy stage to start the java application
FROM openjdk:8 AS deploy
EXPOSE 8021
RUN mkdir /app
COPY --from=build /home/gradle/src/avni-server-api/build/libs/avni-server-0.0.1-SNAPSHOT.jar /app/avni-server-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar","/app/avni-server-0.0.1-SNAPSHOT.jar"]
35 changes: 35 additions & 0 deletions docker/docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3.8"
services:
db:
container_name: postgres
image: postgres:12
volumes:
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 1m30s
timeout: 10s
retries: 3
restart: always
database_build:
container_name: database_init
restart: on-failure
build:
context: ..
image: postgres:12
volumes:
- ../avni-server-api/src/main/resources/build_db.sql:/opt/scripts/build_db.sql
environment:
- PGPASSWORD=password
env_file:
- .env
command: [ "psql", "-h", "$OPENCHS_DATABASE_HOST", "-p", "5432", "-v", "OPENCHS_DATABASE=$OPENCHS_DATABASE", "-v", "OPENCHS_DATABASE_PASSWORD=$OPENCHS_DATABASE_PASSWORD", "-v", "OPENCHS_DATABASE_USER=$OPENCHS_DATABASE_USER","-U", "postgres","-f", "/opt/scripts/build_db.sql" ]

volumes:
db-data:
11 changes: 11 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.8"
services:
web:
container_name: avni_server_api
build: .
image: avni-server:latest
ports:
- "8021:8021"
env_file:
- .env
restart: always