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

Build #4

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -14,3 +14,6 @@ target/*
!.vscode/launch.json
!.vscode/extensions.json
_site/
docker/docker_APP/.m2
docker/docker_swarm/.env

1 change: 1 addition & 0 deletions docker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BUILD SPRING-PETCLINIC VIA DOCKER
23 changes: 23 additions & 0 deletions docker/docker_APP/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:experimental
#---------------------------------------------------------------------------
# Dockefile to build Docker Image of application container for spring_APP running on Ubuntu
#---------------------------------------------------------------------------

# ======= BUILD APP ========
FROM openjdk:8-jdk-alpine as builder

WORKDIR /spring
# Copy SRC and build application
COPY . /spring
# COPY docker/docker_APP/application-mysql.properties /spring/src/main/resources/application-mysql.properties
RUN --mount=type=cache,target=/root/.m2 /spring/mvnw -Dcheckstyle.skip package

# ======= START APP =========

FROM openjdk:8-jre-alpine
# RUN APP

COPY --from=builder /spring/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /app.jar
CMD [ "java", "-jar", "-Dspring.profiles.active=mysql", "/app.jar"]
EXPOSE 8080

39 changes: 39 additions & 0 deletions docker/docker_APP/Dockerfile.reserve
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#---------------------------------------------------------------------------
# Dockefile to build Docker Image of application container for spring_APP running on Ubuntu
#---------------------------------------------------------------------------

# ======== CLONE SRC ==========
FROM alpine/git:v2.26.2 as git

# Setting vars
# Define URL via --build-arg
ARG URL

# Clone repo
RUN mkdir /springapp && \
cd /springapp && \
git clone $URL

# ========= BUILDER ========

FROM openjdk:8-jdk-alpine as builder
# COPY src and .m2
ENV PROJECT_DIR /springapp/spring-petclinic
VOLUME /root/.m2
COPY .m2 /root/.m2
COPY --from=git /springapp /springapp

# Build application
COPY application-mysql.properties $PROJECT_DIR/src/main/resources/application-mysql.properties
RUN cd $PROJECT_DIR && \
./mvnw clean package

# ======= START APP =========

FROM openjdk:8-jre-alpine

# RUN APP
COPY --from=builder /springapp/spring-petclinic/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /app.jar
CMD [ "java", "-jar", "-Dspring.profiles.active=mysql", "/app.jar"]
EXPOSE 8080

19 changes: 19 additions & 0 deletions docker/docker_APP/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
====================== BUILD ===========================

DOCKER_BUILDKIT=1 docker build -t name:tag -f docker/docker_APP/Dockerfile $GIT_URL#$build_branch

============== BUILD RESERVE DOCKERFILE ================

docker build -t name:tag --build-arg URL=$GIT_URL .

================== RUN CONTAINER =======================

docker run -d -p 8080:8080 \
-e DB_HOST=$IP_DB \
-e DB_PORT=$DB_PORT \
-e DB_NAME=$MYSQL_DATABASE \
-e DB_USER=$MYSQL_USER \
-e DB_PASS=$DB_PASS \
--name APP_CONT \
--network my-net \
petclinc-app:tag
8 changes: 8 additions & 0 deletions docker/docker_APP/application-mysql.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# database init, supports mysql too
database=mysql
spring.datasource.url= jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASS}
# SQL is written to be idempotent so this is safe
spring.datasource.initialization-mode=always

15 changes: 15 additions & 0 deletions docker/docker_DB/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#---------------------------------------------------------------------------
# Dockefile to build Docker Image of application container for spring_DB running on mysql image
#---------------------------------------------------------------------------

FROM mysql:latest
# Setting vars
ENV MYSQL_USER $DB_USER
ENV MYSQL_DATABASE $DB_NAME

# Set on run via -e
# MYSQL_PASSWORD
# MYSQL_ROOT_PASSWORD

# EXPOSE 3306

14 changes: 14 additions & 0 deletions docker/docker_DB/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
================== RUN CONTAINER =====================

**** By default MYSQL_USER=$DB_USER, MYSQL_DATABASE=$DB_NAME

docker run \
-e MYSQL_PASSWORD=$DB_PASS \
-e MYSQL_ROOT_PASSWORD=$DB_ROOT_PASS \
-v vol_for_db:/var/lib/mysql/ \
--name DB_CONT \
--network my-net \
--ip $IP_DB \
-d petclinic-db:tag


22 changes: 22 additions & 0 deletions docker/docker_registry/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.3"
services:
registry:
restart: always
image: registry:2
ports:
- 5000:5000
# Define network for registry
networks:
vpcbr:
ipv4_address: 10.5.0.6
# Bind host dir
volumes:
- /registry_doceker:/var/lib/registry
# Create network type bridge for remote access
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16

1 change: 1 addition & 0 deletions docker/docker_swarm/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose.yml for create Swarm stack which includes two services (app, db)
48 changes: 48 additions & 0 deletions docker/docker_swarm/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.1'

# SERVICES
services:
# ------ Configure DB -------
mysql:
image: ${REGISTRY}/petclinic-db:${TAG_DB}
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASS}
# - MYSQL_ALLOW_EMPTY_PASSWORD=true
# - MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASS}
# - MYSQL_DATABASE=${DB_NAME}
volumes:
- /backupDB:/var/lib/mysql/
# ports:
# - "3306:3306"
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 5s
restart_policy:
condition: on-failure
placement:
# constraints: [node.labels.type == db]
constraints: [node.role == manager]
# ----------- Configure APP ----------
appspring:
image: ${REGISTRY}/petclinic-app:${TAG_APP}
ports:
- "8080:8080"
depends_on:
- mysql
environment:
- MYSQL_URL=jdbc:mysql://mysql:${DB_PORT}/petclinic
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PAS=${DB_PASS}
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 5s
restart_policy:
condition: on-failure
placement:
# constraints: [node.labels.type == app]
constraints: [node.role == manager]