fix: Docker network 생성 라인 추가 & WAS Redis 네트워크 옵션 재지정 #23
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 | |
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 [ -z "${sudo docker network ls | grep 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 |