Update main_rajuapp-devops.yml #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is the deployment file | |
name: Docker Build and Push | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build_and_push: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20.x' | |
- name: Install dependencies | |
run: npm install | |
- name: Login to Docker Hub | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
- name: Get short commit hash | |
id: commit_hash | |
run: echo "::set-output name=hash::$(git rev-parse --short HEAD)" | |
- name: Tag with environment and commit hash | |
id: tag_image | |
run: | | |
IMAGE_NAME="https://docker.io/raju00533/backend" | |
COMMIT_HASH=${{ steps.commit_hash.outputs.hash }} | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
ENVIRONMENT="prod" | |
else | |
ENVIRONMENT="dev" | |
fi | |
TAG="${IMAGE_NAME}:${ENVIRONMENT}-${COMMIT_HASH}" | |
docker build -t $TAG . | |
echo $TAG >> .env | |
- name: Push Docker image | |
run: | | |
docker push "${TAG}" | |
- name: Increase version in package.json | |
run: | | |
npm version patch -m "Bump version to %s" | |
- name: Push changes to repository | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "Bump version and Docker image tag" | |
commit_user_name: "Raju00533" | |
commit_user_email: "raju12ghimire@gmail.com" |