-
Notifications
You must be signed in to change notification settings - Fork 2
49 lines (40 loc) · 1.48 KB
/
docker-build-push.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Build and Push Docker Image
on:
push:
branches:
- main
workflow_dispatch:
permissions:
packages: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Step 3: 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.GITHUB_TOKEN }}
# Step 4: Get Date, Build Run Number, and Force Lowercase Repository Name
- name: Get Date and Build Run Number for version tag
id: version
run: |
echo "::set-output name=tag::$(date +'%Y.%m.%d').${{ github.run_number }}"
echo "::set-output name=repo_lower::$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')"
# Step 5: Build the Docker image using the lowercase repository name
- name: Build the Docker image
run: |
docker build -t ghcr.io/${{ steps.version.outputs.repo_lower }}/demo-frontend:${{ steps.version.outputs.tag }} -f demo-frontend/Dockerfile .
# Step 6: Push the Docker image to GitHub Container Registry
- name: Push the Docker image
run: |
docker push ghcr.io/${{ steps.version.outputs.repo_lower }}/demo-frontend:${{ steps.version.outputs.tag }}