Skip to content

Feature/backend news post #93

Feature/backend news post

Feature/backend news post #93

name: Cosmo Front CI/CD
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
jobs:
project-build:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install Dependencies
run: npm install
- name: Build Angular Project
run: npm run build
docker-build:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: project-build
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into the Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: true
tags: cosmopk/cosmo-page-frontend:latest
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: docker-build
steps:
- name: Deploy via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_KEY }}
port: 22
command_timeout: 30m
script: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker pull cosmopk/cosmo-page-frontend:latest
if [ "$(docker ps -qa -f name=cosmo-page-frontend)" ]; then
if [ "$(docker ps -q -f name=cosmo-page-frontend)" ]; then
echo "Container is running -> stopping it..."
docker stop cosmo-page-frontend;
fi
echo "Removing existing container..."
docker rm cosmo-page-frontend;
fi
docker run -d --rm -p 4200:4200 --name cosmo-page-frontend cosmopk/cosmo-page-frontend:latest
exit