Skip to content

[CI/CD] Add restart step #12

[CI/CD] Add restart step

[CI/CD] Add restart step #12

Workflow file for this run

name: Frontend CI/CD Pipeline
#on:
# push:
# paths:
# - 'frontend/FE_Fitness_Tracker/**'
# branches:
# - main
# pull_request:
# paths:
# - 'frontend/FE_Fitness_Tracker/**'
# branches:
# - main
on:
push:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v4
- name: Print Folder Structure
run: |
echo "Printing the folder structure:"
ls -la
- name: Replace apiGatewayBaseUrl in environment.prod.ts
run: |
sed -i "s|apiGatewayBaseUrl:.*|apiGatewayBaseUrl: \\\"http://${{ secrets.DROPLET_IP_ADDRESS }}\\\",|" \
FE_Fitness_Tracker/src/environments/environment.prod.ts
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Dependencies
run: npm install
working-directory: FE_Fitness_Tracker
# - name: Run Tests
# run: npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
# working-directory: FE_Fitness_Tracker
- name: Build
run: npm run build:prod
working-directory: FE_Fitness_Tracker
- name: Print Folder Structure
run: |
echo "Printing the folder structure:"
ls -la
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist_folder
path: FE_Fitness_Tracker/dist/
# Add any deployment steps here, specifying the 'working-directory' if needed
# Local Deployment Steps (for documentation purposes)
- name: Echo Local Deployment Steps
run: |
echo "Pull the latest code:"
echo "git checkout main"
echo "git pull origin main"
echo "Build the Angular application:"
echo "cd path/to/frontend/FE_Fitness_Tracker"
echo "npm install"
echo "npm run build -- --prod"
echo "Deploy locally by copying build artifacts to your local server directory."
echo "Start or restart your local server to serve the new version of the application."
build-and-push-docker:
needs: build-and-test
runs-on: ubuntu-latest
env:
DOCKER_IMAGE_TAG: registry.digitalocean.com/do-ase-registry/frontend
steps:
- name: Checkout project sources
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist_folder
path: FE_Fitness_Tracker/dist
- name: Build Docker Image
run: docker build -f FE_Fitness_Tracker/Dockerfile -t $DOCKER_IMAGE_TAG FE_Fitness_Tracker
- name: GitHub Action for DigitalOcean - doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 600
- name: Push image to DigitalOcean Container Registry
run: docker push $DOCKER_IMAGE_TAG
restart-application:
needs: build-and-push-docker
runs-on: ubuntu-latest
steps:
- name: SSH and Restart Service
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DROPLET_IP_ADDRESS }}
username: root
key: ${{ secrets.DROPLET_SSH_KEY }}
script: |
docker compose -f docker-compose.prod.yaml down
docker compose -f docker-compose.prod.yaml up --pull always --detach