Skip to content

Build and Push Docker Image to DockerHub Registry #200

Build and Push Docker Image to DockerHub Registry

Build and Push Docker Image to DockerHub Registry #200

Workflow file for this run

name: Build and Push Docker Image to DockerHub Registry
on:
schedule:
- cron: '0 0 * * *'
push:
branches:
- main
pull_request:
branches:
- main
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
FRONTEND_REPO_NAME: "assignment_frontend"
BACKEND_REPO_NAME: "assignment_backend"
version: ${{secrets.version}}
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Trivy
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v0.18.3/trivy_0.18.3_Linux-64bit.deb
sudo dpkg -i trivy_0.18.3_Linux-64bit.deb
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '8'
- name: Build Frontend Image
run: |
cd frontend
mv Dockerfile Dockerfile1
sed -i "s/LABEL Maintainer=.*/LABEL Maintainer="${version}"/" Dockerfile1
sed -i "s/ARG release=.*/ARG release="${version}"/" Dockerfile1
docker build -t "${DOCKERHUB_USERNAME}/${FRONTEND_REPO_NAME}:$GITHUB_RUN_NUMBER" -f Dockerfile1 .
# - name: Build Backend Image
# run: |
# cd backend
# docker build -t "${DOCKERHUB_USERNAME}/${BACKEND_REPO_NAME}:$GITHUB_RUN_NUMBER" .
- name: Log in to Docker registry
run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
# - name: Scan container images
# run: |
# trivy image "${DOCKERHUB_USERNAME}/${FRONTEND_REPO_NAME}:$GITHUB_RUN_NUMBER"
# trivy image "${DOCKERHUB_USERNAME}/${BACKEND_REPO_NAME}:$GITHUB_RUN_NUMBER"
- name: Push Frontend Image
run: docker push "${DOCKERHUB_USERNAME}/${FRONTEND_REPO_NAME}:$GITHUB_RUN_NUMBER"
# - name: Push Backend Image
# run: docker push "${DOCKERHUB_USERNAME}/${BACKEND_REPO_NAME}:$GITHUB_RUN_NUMBER"
# frontend-test:
# runs-on: ubuntu-latest
# needs: ['build-and-push']
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Set up Node.js
# uses: actions/setup-node@v2
# with:
# node-version: 8
# - name: Install dependencies
# run: |
# cd frontend
# npm install
# npm install -g @angular/[email protected]
# - name: Build and test frontend
# run: |
# cd frontend
# npm build
# npm test --browsers=ChromeHeadlessNoSandbox
# backend-test:
# runs-on: ubuntu-latest
# needs: ['build-and-push']
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Set up Node.js
# uses: actions/setup-node@v2
# with:
# node-version: 8
# - name: Install dependencies
# run: npm install
# - name: Test backend
# run: |
# cd backend
# npm test
# update-manifest-and-deploy-stage:
# runs-on: ubuntu-latest
# needs: ['build-and-push', 'frontend-test', 'backend-test']
# steps:
# - uses: actions/checkout@v3
# with:
# repository: RohanRusta21/CloudRail_Assignment_Manifest
# ref: 'main'
# token: ${{ secrets.G_TOKEN }}
# - name: setup git config
# run: |
# git config --global user.email "[email protected]"
# git config --global user.name "RohanRusta21"
# echo ${{ github.sha }}
# sed -i "s#${DOCKERHUB_USERNAME}.*#${DOCKERHUB_USERNAME}/${FRONTEND_REPO_NAME}:$GITHUB_RUN_NUMBER#g" frontend-deployment.yml
# sed -i "s#${DOCKERHUB_USERNAME}.*#${DOCKERHUB_USERNAME}/${BACKEND_REPO_NAME}:$GITHUB_RUN_NUMBER#g" backend-deployment.yml
# git add -A
# git commit -am "Update image for Version - $GITHUB_RUN_NUMBER"
# - run: echo ${{ github }}
# - run: git push origin main