-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (60 loc) · 2.59 KB
/
docker-build-push.yml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Build and Push Docker Image
on:
push:
branches:
- "**" # Triggers on all branches
tags:
- "v*.*.*" # Triggers on tag push for versioned tags (e.g., v1.0.0)
jobs:
build-and-push-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Quay.io (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login quay.io -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Get tag or commit SHA
id: vars
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "image_tag=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "image_tag=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Build Docker Image
run: docker build frontend -t fleet-manager:${{ env.image_tag }}
- name: Tag Docker Image (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: docker tag fleet-manager:${{ env.image_tag }} quay.io/rajsinghcpre/fleet-manager:${{ env.image_tag }}
- name: Push Docker Image (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: docker push quay.io/rajsinghcpre/fleet-manager:${{ env.image_tag }}
build-and-push-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Quay.io (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login quay.io -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Get tag or commit SHA
id: vars
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "image_tag=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "image_tag=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Build Docker Image
run: docker build backend -t fleet-manager:${{ env.image_tag }}
- name: Tag Docker Image (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: docker tag fleet-manager:${{ env.image_tag }} quay.io/rajsinghcpre/fleet-manager-backend:${{ env.image_tag }}
- name: Push Docker Image (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: docker push quay.io/rajsinghcpre/fleet-manager-backend:${{ env.image_tag }}