Fix different version for new setup Java. #51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI Workflow Java Maven Docker | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
# see https://docs.github.com/en/actions/language-and-framework-guides/building-and-testing-java-with-maven | |
build: | |
name: Create Maven Package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Set up JDK 1.8 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 8 | |
- name: Cache Maven packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-m2 | |
- name: Build and test with Maven | |
run: mvn -B clean test package | |
- name: Keep JAR file | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Package | |
path: target/ticketmagpie.jar | |
# see https://www.prestonlamb.com/blog/creating-a-docker-image-with-github-actions | |
package: | |
name: Create Docker image | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Download JAR file | |
uses: actions/download-artifact@v2 | |
with: | |
name: Package | |
path: target | |
- name: Build the latest Docker image | |
run: docker build . --file Dockerfile --tag codecop/ticketmagpie:latest | |
- name: Save Docker image | |
run: docker save -o docker_image.tar codecop/ticketmagpie:latest | |
- name: Keep Docker file | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Docker | |
path: docker_image.tar | |
test: | |
name: Test against Docker image | |
runs-on: ubuntu-latest | |
needs: package | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Download Docker file | |
uses: actions/download-artifact@v2 | |
with: | |
name: Docker | |
path: . | |
- name: Load Docker image | |
run: docker load -i docker_image.tar | |
- name: Start the Docker image | |
run: docker run -d -e "SPRING_PROFILES_ACTIVE=hsqldb" -e "MAIL_SMTP_HOST=127.0.0.1" -e "MAIL_SMTP_PORT=11112" --net="host" -p8080:8080 codecop/ticketmagpie:latest | |
# https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container | |
# https://stackoverflow.com/a/48806927/104143 | |
- name: Wait for application to start | |
run: sleep 3 | |
- name: Set up JDK 1.8 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 8 | |
- name: Cache Maven packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-m2 | |
- name: Run system tests | |
run: mvn -B test-compile failsafe:integration-test failsafe:verify -Dmagpie.server=127.0.0.1 -Dmagpie.port=8080 | |
push_to_registry: | |
name: Publish Docker image | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- name: Download Docker file | |
uses: actions/download-artifact@v2 | |
with: | |
name: Docker | |
path: . | |
- name: Load Docker image | |
run: docker load -i docker_image.tar | |
- name: Login to DockerHub Registry | |
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
- name: Push the latest Docker image to Docker Hub | |
run: docker push codecop/ticketmagpie:latest |