Skip to content

[Chore] Action 동작 조건 "push" 만으로만 변경 #16

[Chore] Action 동작 조건 "push" 만으로만 변경

[Chore] Action 동작 조건 "push" 만으로만 변경 #16

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
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/drcal-cicd-was
- name: docker stop container
run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true
- name: docker run new container
run: sudo docker run --name drcal-cicd-was --rm -d -v /home/ubuntu/mini/images:/images -p 8080:8080 -e TZ=Asia/Seoul paul245/drcal-cicd-was
- name: delete lagecy docker image
run: sudo docker system prune -f