Skip to content

Merge pull request #129 from HandTris/#128 #224

Merge pull request #129 from HandTris/#128

Merge pull request #129 from HandTris/#128 #224

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
permissions:
contents: read
jobs:
build-docker-image:
# if: github.event_name != 'pull_request'
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/dev')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: clean bootJar
env:
JASYPT_ENCRYPTOR_PASSWORD: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo -f docker/Dockerfile .
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo
clean-and-run-docker-image-on-ec2:
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
needs: build-docker-image
runs-on: self-hosted
steps:
- name: docker login
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: stop running containers
run: sudo docker stop handtris || true
- name: remove stop container
run: sudo docker rm handtris || true
- name: docker pull
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo
- name: docker run new container
run: sudo docker run --name handtris --restart unless-stopped -d -p 8080:8080 -e JASYPT_ENCRYPTOR_PASSWORD=${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }} ${{ secrets.DOCKERHUB_USERNAME }}/github-actions-demo
env:
JASYPT_ENCRYPTOR_PASSWORD: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}