Rename project name #2
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, Scan, and Push Docker Image with Commit Hash | |
on: | |
push: | |
paths: | |
- '020-GithubActionJavaDockerfileCICD/**' | |
workflow_dispatch: | |
jobs: | |
build-and-scan: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Set up Docker | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v2 | |
# Step 3: Get Git commit hash | |
- name: Get Git commit hash | |
id: vars | |
run: echo "GIT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
# Step 4: Build Docker image with commit hash | |
- name: Build Docker image | |
run: | | |
docker build -t ghcr.io/${{ github.repository_owner }}/current-time-app:${{ env.GIT_COMMIT }} ./020-GithubActionJavaDockerfileCICD | |
# Step 5: Log in to GitHub Container Registry | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.YOUR_GITHUB_TOKEN }} | |
# Step 6: Push Docker image to GHCR | |
- name: Push Docker image | |
run: | | |
docker push ghcr.io/${{ github.repository_owner }}/current-time-app:${{ env.GIT_COMMIT }} |