Skip to content

feat: grafana를 통한 모니터링 환경 구축 #222

feat: grafana를 통한 모니터링 환경 구축

feat: grafana를 통한 모니터링 환경 구축 #222

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 to server
run: |
scp -o StrictHostKeyChecking=no docker-compose.yml ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/docker-compose.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