fix: CD #8
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: Continuous Deployment | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Authorize in Docker | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
- name: Set up JDK 20 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '20' | |
distribution: 'adopt' | |
- name: Build JAR | |
run: ./gradlew bootJar | |
- name: Build Docker image | |
run: docker build --platform linux/amd64 -t almaxgood/cardio-bot:${{ vars.DOCKER_TAG }} . | |
- name: Push Docker image | |
run: docker push almaxgood/cardio-bot:${{ vars.DOCKER_TAG }} | |
- name: Install sshpass | |
run: sudo apt install sshpass | |
- name: Compose .env file | |
run: | | |
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }}>>.env | |
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}>>.env | |
echo MAIN_TOKEN=${{ secrets.MAIN_TOKEN }}>>.env | |
echo LOGGER_TOKEN=${{ secrets.LOGGER_TOKEN }}>>.env | |
echo GUIDE=${{ secrets.GUIDE }}>>.env | |
echo DOCKER_TAG=${{ vars.DOCKER_TAG }}>>.env | |
ls -a | |
cat .env | |
- name: Copy .env file to VM | |
run: sshpass -p ${{ secrets.VM_PASSWORD }} scp ./.env root@${{ secrets.VM_IP }}:~/cardio-bot | |
- name: Run on VM | |
run: sshpass -p ${{ secrets.VM_PASSWORD }} ssh -o StrictHostKeyChecking=no root@${{ secrets.VM_IP }} | |
'cd ~/cardio-bot && | |
docker compose down && | |
docker system prune -a -f --volumes && | |
docker compose up -d' |