Skip to content

Commit 5e9dec5

Browse files
committed
Add GitHub Actions workflow for Docker build and push of microservices-demo-adservice
1 parent 340ba08 commit 5e9dec5

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# .github/workflows/docker-build-push.yaml
2+
name: K8s-Tools | ArgoCD - Docker Build
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: 'Version to use for the Docker image'
9+
required: true
10+
default: 'v1.0.0'
11+
type: choice
12+
options:
13+
- v1.0.0
14+
- v1.0.1
15+
- v1.0.2
16+
push:
17+
branches:
18+
- main
19+
- feature/docs_update
20+
paths:
21+
- 'projects/microservices-demo/src/adservice/Dockerfile'
22+
23+
jobs:
24+
build-push-update:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout code (with all branches)
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
ref: feature/docs_update
32+
33+
- name: Prepare version
34+
id: prep
35+
run: |
36+
if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
37+
VERSION=${{ github.event.inputs.version }}
38+
else
39+
VERSION=${GITHUB_SHA::8}
40+
fi
41+
BUILD_IMAGE=true
42+
echo "VERSION=$VERSION" >> $GITHUB_ENV
43+
echo "IMAGE=anvesh35/microservices-demo-adservice:$VERSION" >> $GITHUB_ENV
44+
echo "LATESTIMAGE=anvesh35/microservices-demo-adservice:latest" >> $GITHUB_ENV
45+
echo "BUILD_IMAGE=$BUILD_IMAGE" >> $GITHUB_ENV
46+
47+
- name: Set up Docker Buildx
48+
if: env.BUILD_IMAGE == 'true'
49+
uses: docker/setup-buildx-action@v2
50+
51+
- name: Login to Docker Hub
52+
if: env.BUILD_IMAGE == 'true'
53+
uses: docker/login-action@v2
54+
with:
55+
username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
password: ${{ secrets.DOCKERHUB_TOKEN }}
57+
58+
- name: Build and push k8s-tools Docker image
59+
if: env.BUILD_IMAGE == 'true'
60+
uses: docker/build-push-action@v4
61+
with:
62+
context: projects/microservices-project/src/adservice/
63+
file: projects/microservices-project/src/adservice/Dockerfile
64+
push: true
65+
tags: ${{ env.IMAGE }}
66+
platforms: linux/amd64,linux/arm64
67+
build-args: |
68+
VERSION=${{ env.VERSION }}
69+

0 commit comments

Comments
 (0)