Skip to content

OrangeHRM PROD Image Build Workflow #27

OrangeHRM PROD Image Build Workflow

OrangeHRM PROD Image Build Workflow #27

name: OrangeHRM PROD Image Build Workflow
on:
push:
branches: [ php-7.4-rhel-8 ]
schedule:
- cron: '30 0 * * MON' # 0030 in UTC, 0600 in IST
workflow_dispatch:
env:
REGISTRY: hub.docker.com
DOCKER_HUB_REPO: "orangehrm/prod-environment-redhat"
LATEST_TAG_NAME: "php-7.4-latest"
UPSTREAM_REPO: "orangehrm/orangehrm-prod-environment"
UPSTREAM_BRANCH: "refs/heads/php-7.4-rhel-8"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Verify prerequisites
run: |
docker --version
docker compose version
composer --version
- name: Install test suite dependencies
run: composer install
- name: Build docker image
run: |
docker build -t ${{ env.DOCKER_HUB_REPO }}:${{ env.LATEST_TAG_NAME }} --build-arg REDHAT_USERNAME=${{ secrets.REDHAT_USERNAME }} --build-arg REDHAT_PASSWORD=${{ secrets.REDHAT_PASSWORD }} docker-image
- name: Spin up the container
run: |
docker compose up -d
docker ps -a
- name: Get installed php version
run: echo "PHP_VERSION=php-$(docker exec $(docker ps --format '{{.Names}}' | head -n 1) php -r 'echo PHP_VERSION;')" >> $GITHUB_ENV
- name: Set TAG_NAME with date
run: |
CURRENT_DATE=$(date +'%d%m%y')
echo VERSION_TAG_NAME="${{ env.PHP_VERSION }}-${CURRENT_DATE}" >> $GITHUB_ENV
- name: Copy the report file
run: |
docker cp $(docker ps --format '{{.Names}}' | head -n 1):/var/installed_packages_detailed_report.txt installed_packages_detailed_report.txt
- name: Run unit test suite
run: |
sleep 10s
php vendor/bin/codecept run unit
- name: New image with a version tag & latest tag
run: |
docker tag ${{ env.DOCKER_HUB_REPO }}:${{ env.LATEST_TAG_NAME }} ${{ env.DOCKER_HUB_REPO }}:${{ env.VERSION_TAG_NAME }}
- name: Docker hub login
if: ${{ github.repository == env.UPSTREAM_REPO && github.ref == env.UPSTREAM_BRANCH }}
run: docker login -u=${{ secrets.DOCKER_HUB_USERNAME }} -p=${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Deploy changes to the docker hub with version tag
if: ${{ github.repository == env.UPSTREAM_REPO && github.ref == env.UPSTREAM_BRANCH }}
run: |
docker push ${{ env.DOCKER_HUB_REPO }}:${{ env.VERSION_TAG_NAME }}
echo 'SUCCESS - IMAGE WAS PUBLISHED ${{ env.DOCKER_HUB_REPO }}:${{ env.VERSION_TAG_NAME }}'
- name: Deploy changes to the docker hub with latest tag
if: ${{ github.repository == env.UPSTREAM_REPO && github.ref == env.UPSTREAM_BRANCH }}
run: |
docker push ${{ env.DOCKER_HUB_REPO }}:${{ env.LATEST_TAG_NAME }}
echo 'SUCCESS - IMAGE WAS PUBLISHED ${{ env.DOCKER_HUB_REPO }}:${{ env.LATEST_TAG_NAME }}'
- name: Docker hub logout
if: ${{ github.repository == env.UPSTREAM_REPO && github.ref == env.UPSTREAM_BRANCH }}
run: docker logout
- name: Get the File Names
run: ls -la ./html
- name: Send the email notification
if: always()
uses: dawidd6/action-send-mail@v2
with:
# mail server settings
server_address: smtp.gmail.com
server_port: 465
# user credentials
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
# email subject
subject: ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
# email body as text
body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
# comma-separated string, send email to
to: ${{ vars.EMAIL_RECIPIENTS }}
# from email name
from: DockHRM Automator
attachments : installed_packages_detailed_report.txt