Merge remote-tracking branch 'origin/refactor' into refactor #31
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
push: | |
branches: [ "refactor" ] | |
permissions: | |
contents: read | |
jobs: | |
build-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
shell: bash | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/drcal-cicd-was . | |
- 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 }}/drcal-cicd-was | |
run-docker-image-on-ec2: | |
needs: build-docker-image | |
runs-on: self-hosted | |
steps: | |
- name: docker pull WAS | |
run: docker pull ${{ secrets.DOCKERHUB_USERNAME }}/drcal-cicd-was | |
- name: docker pull Redis | |
run: docker pull redis | |
- name: docker stop container | |
run: docker stop $(docker ps -q) 2>/dev/null || true | |
- name: check and create network | |
run: | | |
if ! docker network ls | grep -q drcal-network; then | |
echo "no network found | create new docker network" | |
docker network create drcal-network | |
else | |
echo "drcal-network already exists" | |
fi | |
- name: docker run WAS container | |
run: docker run --name drcal-cicd-was --rm --network drcal-network -d -v /home/ubuntu/mini/images:/images -p 8080:8080 -e TZ=Asia/Seoul ${{ secrets.DOCKERHUB_USERNAME }}/drcal-cicd-was | |
- name: docker run Redis container | |
run: docker run --name test-redis --network drcal-network --rm -d redis | |
- name: delete lagecy docker image | |
run: docker system prune -f |