👷 feat: add k8s.yaml #34
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: Baekjoon-Bot CI/CD | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
CI: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v3.8.1 | |
with: | |
node-version: "18.x" | |
- name: Install modules | |
run: npm ci | |
- name: Unit test | |
run: npm test | |
- name: Docker login | |
uses: docker/login-action@v3.0.0 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
logout: true | |
- name: Build and push to DockerHub | |
run: | | |
docker build -t ${{ secrets.PROJECT_NAME }} . | |
docker tag ${{ secrets.PROJECT_NAME }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}:latest | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }}:latest | |
CD: | |
needs: CI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to EC2 / Check bot status | |
uses: appleboy/ssh-action@v1.0.0 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
echo "DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}" > env.list | |
echo "RDS_ENDPOINT=${{ secrets.RDS_ENDPOINT }}" >> env.list | |
echo "RDS_USER=${{ secrets.RDS_USER }}" >> env.list | |
echo "RDS_PASSWORD=${{ secrets.RDS_PASSWORD }}" >> env.list | |
echo "RDS_DB=${{ secrets.RDS_DB }}" >> env.list | |
echo "BASE_URL=${{ secrets.BASE_URL }}" >> env.list | |
echo "TZ=Asia/Seoul" >> env.list | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
sudo chmod 777 ./deploy.sh | |
sudo bash ./deploy.sh | |
sudo docker image prune -f |