feat: 모니터링과 서버 환경 분리 #236
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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- 'feature/*' | |
- 'chore/*' | |
pull_request: | |
branches: | |
- dev | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: List files after checkout | |
run: ls -la | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew build | |
env: | |
JASYPT_PASSWORD: ${{ secrets.JASYPT_PASSWORD }} | |
version: ${{ secrets.VERSION }} | |
buildTime: ${{ secrets.BUILDTIME }} | |
- name: Run tests | |
run: ./gradlew test | |
env: | |
JASYPT_PASSWORD: ${{ secrets.JASYPT_PASSWORD }} | |
version: ${{ secrets.VERSION }} | |
buildTime: ${{ secrets.BUILDTIME }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: packaged-jar | |
path: build/libs/*.jar | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_test | |
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'dev' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Check JASYPT_PASSWORD environment variable | |
run: | | |
if [ -z "${{ secrets.JASYPT_PASSWORD }}" ]; then | |
echo "JASYPT_PASSWORD is not set." | |
exit 1 | |
else | |
echo "JASYPT_PASSWORD is set." | |
fi | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: packaged-jar | |
path: build/libs | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Set TAG | |
run: echo "TAG=${{ github.sha }}" >> $GITHUB_ENV | |
- name: Print TAG | |
run: echo "The value of TAG is $TAG" | |
- name: Build and push Docker image | |
run: | | |
echo "Building and pushing Docker image with TAG: $TAG" | |
docker build -t climingo/climingo:$TAG . | |
docker push climingo/climingo:$TAG | |
- name: Setup SSH Agent | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Upload docker-compose.yml and prometheus.yml to server | |
run: | | |
scp -o StrictHostKeyChecking=no docker-compose.yml ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/docker-compose.yml | |
scp -o StrictHostKeyChecking=no promtail-config.yml ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/promtail-config.yml | |
- name: Executing remote SSH commands using ssh-agent | |
run: | | |
ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_HOST }} << EOF | |
echo "Deploying Docker image with TAG: $TAG" | |
docker pull climingo/climingo:$TAG | |
cd /home/ubuntu | |
docker-compose down || true | |
export TAG=$TAG | |
export JASYPT_PASSWORD=${{ secrets.JASYPT_PASSWORD }} | |
export BUILDTIME="$(date)" | |
docker-compose up -d | |
EOF |