Skip to content

fix: echo 커맨드 sudo 추가 #34

fix: echo 커맨드 sudo 추가

fix: echo 커맨드 sudo 추가 #34

Workflow file for this run

name: Deploy
on:
push:
branches: [ "ci/cd" ]
pull_request:
branches: [ "ci/cd" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
# 기본 체크아웃
- name: Checkout
uses: actions/checkout@v3
# 폴더 정보 확인
- name: List the repository structure
run: ls -R
# JDK 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Gradlew 실행 허용
- name: Grant execute permission for gradlew
run: chmod +x ./wabi/gradlew
# 환경 변수 설정
- name: Set environment values
run: |
touch ./wabi/src/main/resources/env.properties
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" >> ./env.properties
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" >> ./env.properties
echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" >> ./env.properties
echo "JWT_KEY=${{ secrets.JWT_KEY }}" >> ./env.properties
echo "JWT.EXPIRATION.HOURS=${{ secrets.JWT_EXPIRATION_HOURS }}" >> ./env.properties
echo "JWT.ISSUER=${{ secrets.JWT_ISSUER }}" >> ./env.properties
shell: bash
# Gradle build (Test 제외)
- name: Build with Gradle
run: |
ls
cd wabi
ls
./gradlew clean build -x test
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
cd wabi
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest . # 이미지에 latest 태그를 추가
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest seongwonyoon/wabi:${GITHUB_SHA::7} # GITHUB_SHA를 이용한 커밋 태그 추가
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest # latest 버전 푸시
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} # 커밋 해시 버전 푸시
# Deploy
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
envs: GITHUB_SHA
script: |
#!/bin/bash
ls
cd /
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}
# Create .env file in the correct directory
sudo echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" > .env
sudo echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" >> .env
sudo echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" >> .env
sudo echo "JWT_KEY=${{ secrets.JWT_KEY }}" >> .env
sudo echo "JWT_EXPIRATION_HOURS=${{ secrets.JWT_EXPIRATION_HOURS }}" >> .env
sudo echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" >> .env
sudo echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> .env
sudo echo "DOCKERHUB_REPOSITORY=${{ secrets.DOCKERHUB_REPOSITORY }}" >>
if [ -f "docker-compose.yml" ]; then
sudo docker-compose down
sudo docker-compose up -d
else
echo "docker-compose.yml not found in the current directory."
exit 1
fi