Skip to content

Merge pull request #5 from sdfgx123/feature/#4 #25

Merge pull request #5 from sdfgx123/feature/#4

Merge pull request #5 from sdfgx123/feature/#4 #25

Workflow file for this run

# 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
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: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/drcal-cicd-was
- name: docker pull Redis
run: sudo docker pull redis
- name: docker stop container
run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true
- name: check and create network
run: |
if ! sudo docker network ls | grep -q drcal-network; then
echo "no network found | create new docker network"
sudo docker network create drcal-network
else
echo "drcal-network already exists"
fi
- name: docker run WAS container
run: sudo docker run --name drcal-cicd-was --rm --network drcal-network -d -v /home/ubuntu/mini/images:/images -p 8080:8080 -e TZ=Asia/Seoul paul245/drcal-cicd-was
- name: docker run Redis container
run: sudo docker run --name test-redis --network drcal-network --rm -d redis
- name: delete lagecy docker image
run: sudo docker system prune -f