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

[IL-84]Environments #92

Merged
merged 30 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
10 changes: 7 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
APP_ENV=prod
APP_ENV=dev
APP_VERSION=0.0.1-SNAPSHOT
HUB=zufarexplainedit
TAG=1.0.0-fix-docker-environment
voltwatt marked this conversation as resolved.
Show resolved Hide resolved
DATASOURCE_URL=jdbc:postgresql://postgresdb:5432/testdb
TAG=1.0.0
DATASOURCE_URL=jdbc:postgresql://postgresdb:5432/testdb?serverTimezone=UTC
DATASOURCE_USERNAME=postgres
DATASOURCE_PASSWORD=postgres
SERVER_PORT=8083
41 changes: 32 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
#
# Build stage with Maven
#
FROM maven:3.8.3-openjdk-17 as maven_build
ENV HOME=/opt/app
RUN mkdir -p $HOME
WORKDIR $HOME
ADD pom.xml $HOME
RUN mvn verify --fail-never
ADD ./ $HOME
RUN mvn package
COPY pom.xml ./
COPY .env ./
RUN set -ex; \
export APP_ENV=$(grep APP_ENV .env | cut -d '=' -f2) && \
mvn dependency:go-offline -P${APP_ENV}
COPY . ./
RUN chmod +x /opt/app/mvnw
RUN set -ex; \
export APP_ENV=$(grep APP_ENV .env | cut -d '=' -f2) && \
mvn versions:set-property -Dproperty=project.version -DnewVersion=${APP_VERSION} && \
mvn package -P${APP_ENV}

FROM eclipse-temurin:17-jre-jammy
WORKDIR $HOME
COPY --from=maven_build /opt/app/target/online-store-0.0.1-SNAPSHOT.jar /opt/app/online-store-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/opt/app/online-store-0.0.1-SNAPSHOT.jar" ]
#
# Production stage
#
FROM eclipse-temurin:17-jre-jammy as prod
WORKDIR /opt/app
RUN apt-get update && \
apt-get install -y netcat && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=maven_build /opt/app/target/*.jar /opt/app/app.jar
COPY --from=maven_build /opt/app/.env /opt/app/.env
COPY --from=maven_build /opt/app/docker/docker-entrypoint.sh /opt/app/docker-entrypoint.sh
RUN chmod +x /opt/app/docker-entrypoint.sh

#
# Entrypoint
#
ENTRYPOINT ["/opt/app/docker-entrypoint.sh"]
7 changes: 6 additions & 1 deletion docker-compose.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ services:
- online-store-network
volumes:
- 'db:/var/lib/postgresql/data'
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 30s
timeout: 10s
retries: 5

sonarqube:
image: sonarqube:latest
container_name: onlinestore-sonarqube
ports:
- "9011:9011"
- "9000:9000"
networks:
- online-store-network
volumes:
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ services:
- '8083:8083'
networks:
- online-store-network
environment:
DATASOURCE_URL: ${DATASOURCE_URL}
26 changes: 26 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -e

APP_ENV=$(grep APP_ENV /opt/app/.env | cut -d '=' -f2)
APP_VERSION=$(grep APP_VERSION /opt/app/.env | cut -d '=' -f2)
DATASOURCE_URL=$(grep DATASOURCE_URL /opt/app/.env | cut -d '=' -f2)

export APP_ENV
export APP_VERSION
export DATASOURCE_URL

retries=0
max_retries=20

while ! nc -z postgresdb 5432; do
retries=$((retries + 1))
if [ $retries -ge $max_retries ]; then
echo "PostgresDB is not reachable. Exiting after $max_retries retries."
exit 1
fi

echo "Waiting for PostgresDB... Retry $retries"
sleep 3
done

exec java -jar /opt/app/app.jar
Loading
Loading