Skip to content

Merge branch 'integration' of github.com:DrInTech22/full-stack-gitops… #1

Merge branch 'integration' of github.com:DrInTech22/full-stack-gitops…

Merge branch 'integration' of github.com:DrInTech22/full-stack-gitops… #1

Workflow file for this run

name: CI Pipeline
on:
workflow_dispatch:
push:
branches:
- 'integration'
path:
- './frontend/**'
jobs:
# Frontend Pipeline
build-and-test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install dependencies
run: |
cd frontend
npm install
- name: Lint code
run: |
cd frontend
npm run lint | tee /dev/null
- name: Build
run: |
cd frontend
npm run build
build-push-image:
name: Build & Push Image
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set tags as environment variables
run: |
COMMIT_SHA=$(git rev-parse --short HEAD)
echo "IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/frontend" >> $GITHUB_ENV
echo "IMAGE_TAG_1=latest" >> $GITHUB_ENV
echo "IMAGE_TAG_2=${{ github.run_number }}-$COMMIT_SHA" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}:frontend"
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_1 }}, ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_2 }}
update-deployment:
name: Update Deployment File
runs-on: ubuntu-latest
needs: build-push-image
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set environment variables
run: |
COMMIT_SHA=$(git rev-parse --short HEAD)
echo "IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/frontend" >> $GITHUB_ENV
echo "IMAGE_TAG_2=${{ github.run_number }}-$COMMIT_SHA" >> $GITHUB_ENV
- name: Update Deployment YAML
run: |
sed -i "s|image: ${{ env.IMAGE_NAME }}:.*|image: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_2 }}|" ./ansible/compose.yml.j2
- name: Commit and Push Changes
run: |
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}"
git config --global user.name "${{ secrets.GIT_USER_NAME }}"
git add ./ansible/compose.yml.j2
git commit -m "Update Docker Image Tag to ${{ env.IMAGE_TAG_2 }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}