Fixing deployment step in CI #7
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: backend-pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [18.19.1] | |
mongodb-version: ['6.0'] | |
steps: | |
- name: Git checkout | |
uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Start MongoDB | |
uses: supercharge/mongodb-github-action@1.10.0 | |
with: | |
mongodb-version: ${{ matrix.mongodb-version }} | |
- name: Install dependencies | |
run: npm install | |
env: | |
DB_URI: mongodb://127.0.0.1:27017/astro-db | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
publish: | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5.1.0 | |
with: | |
context: . | |
push: true | |
tags: eddsnx3/astro-backend:latest | |
deploy: | |
needs: publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: SSH and Redeploy | |
uses: appleboy/ssh-action@v1.0.0 | |
with: | |
host: ${{ secrets.MY_HOST }} | |
username: ${{ secrets.MY_USERNAME }} | |
key: ${{ secrets.MY_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
sudo su | |
cd ~/Astrolabs-Backend-Nodejs | |
docker compose down | |
docker compose pull | |
docker compose up -d | |
docker image prune -a --force |