Skip to content

Merge pull request #3 from Nexters/feature/2 #1

Merge pull request #3 from Nexters/feature/2

Merge pull request #3 from Nexters/feature/2 #1

name: Bottles Deploy Workflow
on:
push:
branches:
- develop
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
shell: bash
- name: Build with gradle
run: ./gradlew clean build
shell: bash
- name: Set Date and Time for Tag
run: echo "DATETIME_TAG=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- name: Docker build & push
env:
DOCKER_TAG: ${{ env.DATETIME_TAG }}
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build --platform linux/amd64 -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/bottles:$DOCKER_TAG .
docker push ${{ secrets.DOCKER_USERNAME }}/bottles:$DOCKER_TAG
- name: Transfer file using SCP
env:
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_USER_NAME: ${{ secrets.SERVER_USER_NAME }}
SERVER_PRIVATE_KEY: ${{ secrets.SERVER_PRIVATE_KEY }}
run: |
echo "$SERVER_PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
scp -o StrictHostKeyChecking=no -i private_key.pem ./docker-compose.yml $SERVER_USER_NAME@$SERVER_HOST:/home/$SERVER_USER_NAME/docker
scp -o StrictHostKeyChecking=no -i private_key.pem ./deploy.sh $SERVER_USER_NAME@$SERVER_HOST:/home/$SERVER_USER_NAME/deploy
scp -o StrictHostKeyChecking=no -i private_key.pem ./notify_error.sh $SERVER_USER_NAME@$SERVER_HOST:/home/$SERVER_USER_NAME/deploy
rm private_key.pem
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER_NAME }}
key: ${{ secrets.SERVER_PRIVATE_KEY }}
script: |
export SERVER_NGINX_CONF=${{ secrets.SERVER_NGINX_CONF }}
export SERVER_USER_NAME=${{ secrets.SERVER_USER_NAME }}
export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}
export DOCKER_TAG=${{ env.DATETIME_TAG }}
export DB_DATABASE=${{ secrets.DB_DATABASE }}
export DB_USER_NAME=${{ secrets.DB_USER_NAME }}
export DB_PASSWORD=${{ secrets.DB_PASSWORD }}
export DISCORD_WEBHOOK_URL=${{ secrets.DISCORD_WEBHOOK_URL }}
cd /home/$SERVER_USER_NAME/deploy
sudo chmod +x deploy.sh notify_error.sh
./deploy.sh