Configure docker and ci

This commit is contained in:
Allan 2021-07-14 20:55:52 +02:00
parent e7c879ed3a
commit a805b34885
4 changed files with 176 additions and 0 deletions

65
.github/workflows/ci-dev.yml vendored Normal file
View file

@ -0,0 +1,65 @@
name: Build and Publish Docker Image
on:
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Build with Maven
run: |
mvn -B clean package --file pom.xml
echo "::set-output name=APP_VERSION::$(mvn --file pom.xml -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)"
id: build-version
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: spring-petclinic-jar
path: target/*.jar
- name: Save version
uses: noobly314/share-data@v1
with:
share-id: app_version
mode: set
key: version
value: ${{ steps.build-version.outputs.APP_VERSION }}
docker:
name: Docker Build and Push
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Get Version
id: get-version
uses: noobly314/share-data@v1
with:
share-id: app_version
mode: get
key: version
- name: Download Artifact
uses: actions/download-artifact@v2
with:
name: spring-petclinic-jar
path: target
- name: Docker Login
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
- name: Docker Build Version DEV
run: docker build -t allanweber/spring-petclinic:${{ steps.get-version.outputs.data }} -f docker/Dockerfile .
- name: Build and Push Version
run: docker push allanweber/spring-petclinic:${{ steps.get-version.outputs.data }}
- name: Delete Artifact
uses: geekyeggo/delete-artifact@v1
with:
name: spring-petclinic-jar

74
.github/workflows/ci-master.yml vendored Normal file
View file

@ -0,0 +1,74 @@
name: Build and Publish Docker Image
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Build with Maven
run: |
mvn -B clean package --file pom.xml
echo "::set-output name=APP_VERSION::$(mvn --file pom.xml -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)"
id: build-version
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: spring-petclinic-jar
path: target/*.jar
- name: Create Tag
uses: negz/create-tag@v1
with:
version: ${{ steps.build-version.outputs.APP_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Save version
uses: noobly314/share-data@v1
with:
share-id: app_version
mode: set
key: version
value: ${{ steps.build-version.outputs.APP_VERSION }}
docker:
name: Docker Build and Push
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Get Version
id: get-version
uses: noobly314/share-data@v1
with:
share-id: app_version
mode: get
key: version
- name: Download Artifact
uses: actions/download-artifact@v2
with:
name: spring-petclinic-jar
path: target
- name: Docker Login
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASS }}
- name: Docker Build Version PRD
run: docker build -t allanweber/spring-petclinic:${{ steps.get-version.outputs.data }} -f docker/Dockerfile .
- name: Build and Push Version
run: docker push allanweber/spring-petclinic:${{ steps.get-version.outputs.data }}
- name: Docker Build Latest
run: docker build -t allanweber/spring-petclinic:latest -f docker/Dockerfile .
- name: Docker Push Latest
run: docker push allanweber/spring-petclinic:latest
- name: Delete Artifact
uses: geekyeggo/delete-artifact@v1
with:
name: spring-petclinic-jar

23
RUNME.md Normal file
View file

@ -0,0 +1,23 @@
# How to run with docker
## To Run it locally
1. Create a docker network: `docker network create my-network`
2. Start a mysql container in the specified network: `docker run -p 3306:3306 --name petclinicdb --net=my-network -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic mysql:5.7.8`
3. Run the app in the specified network: `docker run -p 8080:8080 --name spring-petclinic --net=my-network -e SPRING_PROFILES_ACTIVE=mysql -e MYSQL_URL='jdbc:mysql://petclinicdb:3306/petclinic' allanweber/spring-petclinic:2.4.5`
## Build image and deploy it
1. Build version: `docker build -t allanweber/spring-petclinic:<version> -f docker/Dockerfile .`
2. Build latest: `docker build -t allanweber/spring-petclinic:latest -f docker/Dockerfile .`
3. Deploy version to registry: `docker push allanweber/spring-petclinic:<version>`
4. Deploy latest to registry: `docker push allanweber/spring-petclinic:latest`
* **Run prd**: docker run -p 8080:8080 --name spring-petclinic -d -e SPRING_PROFILES_ACTIVE=mysql -e MYSQL_URL=0.0.0.0:3306 -e MYSQL_USER=petclinic -e MYSQL_PASS=petclinic allanweber/spring-petclinic:2.4.5
* **Remove local container**: `docker rm -f spring-petclinic`
docker run -p 8080:8080 --name spring-petclinic --net=my-network -e SPRING_PROFILES_ACTIVE=mysql -e MYSQL_URL='jdbc:mysql://petclinicdb:3306/petclinic' -e MYSQL_USER=petclinic -e MYSQL_PASS=petclinic allanweber/spring-petclinic:2.4.5

14
docker/Dockerfile Normal file
View file

@ -0,0 +1,14 @@
FROM adoptopenjdk/openjdk11:alpine-jre
EXPOSE 8080
ARG Xmx="-Xmx500m"
ARG Xms="-Xmx500m"
ENV JAVA_OPTS "$Xmx \
$Xms \
-XX:+UseParallelGC"
ADD target/spring-petclinic*.jar spring-petclinic.jar
CMD [ "sh", "-c", "java $JAVA_OPTS -jar spring-petclinic.jar" ]