Update cicd.yaml #5
Workflow file for this run
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
name: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- '**' # Triggers on push to any branch | |
pull_request: | |
branches: | |
- master # Triggers on PR to master branch | |
workflow_dispatch: # Manually trigger the workflow | |
jobs: | |
build: | |
if: github.ref != 'refs/heads/master' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build Docker image | |
run: docker build -t server . | |
deploy: | |
needs: build # Ensure deploy job waits for build job | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/master' | |
steps: | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Docker image | |
run: docker push server:latest |