Skip to content

Merge branch 'main' into OurServices #35

Merge branch 'main' into OurServices

Merge branch 'main' into OurServices #35

Workflow file for this run

name: Containerize and Deploy
on:
push:
branches:
- main
jobs:
api:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker Login
uses: docker/login-action@v3.1.0
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push API
uses: docker/build-push-action@v5.3.0
with:
context: ./api
file: ./api/Dockerfile
push: true
tags: ghcr.io/${{github.repository_owner}}/g-yachts-api:${{github.sha}}
web:
runs-on: ubuntu-latest
needs: api
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker Login
uses: docker/login-action@v3.1.0
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push web
uses: docker/build-push-action@v5.3.0
with:
context: ./web
file: ./web/Dockerfile
push: true
tags: ghcr.io/${{github.repository_owner}}/g-yachts-web:${{github.sha}}
deploy:
runs-on: ubuntu-latest
needs: web
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{secrets.SERVER_IP}}
username: ${{secrets.SERVER_USER}}
password: ${{secrets.SERVER_PASSWORD}}
script: |
sudo docker pull ghcr.io/${{github.repository_owner}}/g-yachts-api:${{github.sha}}
sudo docker pull ghcr.io/${{github.repository_owner}}/g-yachts-web:${{github.sha}}
sudo docker stop g-yachts-web g-yachts-api || true
sudo docker rm g-yachts-web g-yachts-api || true
sudo docker run -d --name g-yachts-api --network="host" -p 5001:5001 -e MONGO_HOST=${{secrets.MONGO_HOST}} -e MONGO_DB=${{ vars.MONGO_DB }} -e MONGO_USER=${{ vars.MONGO_USER }} -e MONGO_PASS=${{secrets.MONGO_PASS}} -e WEB_URL=${{vars.WEB_URL}} ghcr.io/${{github.repository_owner}}/g-yachts-api:${{github.sha}}
sudo docker run -d --name g-yachts-web --network="host" -p 3000:3000 -e NEXT_PUBLIC_API_URL=${{ vars.API_URL }} -e NEXT_PUBLIC_CURRENCY_API_KEY=${{secrets.CURRENCY_API}} ghcr.io/${{github.repository_owner}}/g-yachts-web:${{github.sha}}