Skip to content

Commit

Permalink
[CI/CD] Use reusable configs
Browse files Browse the repository at this point in the history
  • Loading branch information
SyzSteM committed Jan 24, 2024
1 parent 6c54ef7 commit 917ec82
Showing 1 changed file with 20 additions and 66 deletions.
86 changes: 20 additions & 66 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name: Frontend CI/CD Pipeline

#on:
# push:
# paths:
# - 'frontend/FE_Fitness_Tracker/**'
on:
push:
paths:
- '.github/workflows/*.yml'
- 'frontend/FE_Fitness_Tracker/**'
# branches:
# - main
# pull_request:
# paths:
# - 'frontend/FE_Fitness_Tracker/**'
pull_request:
paths:
- '.github/workflows/*.yml'
- 'frontend/FE_Fitness_Tracker/**'
# branches:
# - main

on:
push:

jobs:
build-and-test:
runs-on: ubuntu-latest
Expand All @@ -30,7 +29,7 @@ jobs:
- 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
FE_Fitness_Tracker/src/environments/environment.prod.ts
- name: Setup Node.js environment
uses: actions/setup-node@v4
Expand Down Expand Up @@ -60,64 +59,19 @@ jobs:
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
- name: Build and Push Docker Image
uses: 2023-WS-ASE/workout-tracker/.github/workflows/docker-build-and-push.yml@main
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
docker_image_tag: registry.digitalocean.com/do-ase-registry/frontend
build_artifact_name: dist_folder
build_artifact_path: FE_Fitness_Tracker/dist
docker_build_dockerfile_path: FE_Fitness_Tracker/Dockerfile
docker_build_context_path: FE_Fitness_Tracker

- name: Restart Services with Docker Compose
uses: 2023-WS-ASE/workout-tracker/.github/workflows/docker-compose-restart.yml@main

0 comments on commit 917ec82

Please sign in to comment.