#173 chore: docker 이미지 빌드 먼저 하게 수정 #110
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
name: TogetUp-Server-Dev CI/CD | |
on: | |
push: | |
branches: [ "main" ,"env/docker-cd" ] | |
env: | |
S3_BUCKET_NAME: togetup-storage | |
FILE_PATH: /home/ubuntu/app/ | |
FILE_NAME: TogetUp-0.0.1-SNAPSHOT.jar | |
jobs: | |
deploy_dev: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Get CurrentTime | |
uses: 1466587594/get-current-time@v2 | |
id: current-time | |
with: | |
format: YYYY-MM-DDTHH-mm-ss | |
utcOffset: "+09:00" | |
- name: Show Current Time | |
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}" | |
shell: bash | |
- name: make application.yml | |
run: | | |
## create application.yml | |
mkdir -p ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
echo '${{ secrets.TOGETUP_DEV_APPLICATION }}' >> ./application.yml | |
cat ./application.yml | |
shell: bash | |
- name: Gradle caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/togetupdev . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Docker push | |
run: | | |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/togetupdev | |
- name: Deploy to dev | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
script: | | |
sudo docker ps -qa | grep -q . && sudo docker rm -f $(docker ps -qa) | |
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_DEV}} | |
docker-compose up -d | |
sudo docker image prune -f | |