Merge pull request #40 from paulasuarezp/devFront #43
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: CI for TFG | |
on: | |
push: | |
branches: | |
- main | |
release: | |
types: [published] | |
jobs: | |
docker-push-webapp: | |
name: Push webapp Docker Image to GitHub Packages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js 20 | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
- name: Log in to GitHub Docker registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./webapp | |
push: true | |
tags: ghcr.io/${{ github.repository_owner }}/webapp:latest | |
build-args: | | |
API_URI=${{ secrets.API_URI }} | |
docker-push-restapi: | |
name: Push restapi Docker Image to GitHub Packages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js 20 | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
- name: Log in to GitHub Docker registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./restapi | |
push: true | |
tags: ghcr.io/${{ github.repository_owner }}/restapi:latest | |
build-args: | | |
MONGO_URI=${{ secrets.MONGO_URI }} | |
TOKEN_SECRET=${{ secrets.TOKEN_SECRET }} | |
PAYPAL_CLIENT_ID=${{ secrets.PAYPAL_CLIENT_ID }} | |
PAYPAL_CLIENT_SECRET=${{ secrets.PAYPAL_CLIENT_SECRET }} | |
PAYPAL_TOKEN=${{ secrets.PAYPAL_TOKEN }} | |
NODE_ENV=production | |
deploy: | |
name: Deploy over SSH | |
runs-on: ubuntu-latest | |
needs: [docker-push-restapi,docker-push-webapp] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create docker-compose.yml | |
run: echo "${{ secrets.DOCKER_COMPOSE_DEPLOY }}" > docker-compose.yml | |
- name: Docker Login on Remote | |
uses: fifsky/ssh-action@master | |
with: | |
host: ${{ secrets.DEPLOY_HOST }} | |
user: ${{ secrets.DEPLOY_USER }} | |
key: ${{ secrets.DEPLOY_KEY }} | |
command: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Deploy over SSH | |
uses: fifsky/ssh-action@master | |
with: | |
host: ${{ secrets.DEPLOY_HOST }} | |
user: ${{ secrets.DEPLOY_USER }} | |
key: ${{ secrets.DEPLOY_KEY }} | |
command: | | |
sudo docker-compose stop | |
sudo docker-compose rm -f | |
sudo docker-compose pull | |
sudo docker-compose up -d |