#173 env: prod 서버 job 이름 변경 #6
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-Prod CI/CD | |
on: | |
push: | |
branches: [ "product","env/docker-cd" ] | |
env: | |
S3_BUCKET_NAME: togetup-storage | |
FILE_PATH: /home/ubuntu/app/ | |
FILE_NAME: TogetUp-0.0.1-SNAPSHOT.jar | |
jobs: | |
deploy_prod: | |
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_PROD_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: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Docker build & push | |
run: | | |
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/togetupprod . | |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/togetupprod | |
- name: Deploy to prod | |
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 }}/togetupprod | |
sudo docker-compose up -d | |
sudo docker image prune -f | |