Skip to content

Commit 50f6569

Browse files
Merge pull request #77 from anveshmuppeda/dev
Add New workflow | Echo-Pod | Docker Build & Push
2 parents 965daa4 + a2bf703 commit 50f6569

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

.github/workflows/docker-build-push-update.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# .github/workflows/docker-build-push-update.yaml
2-
name: App1 Docker Build, Push & Update Manifests
2+
name: FluxCD Demo | App1 Docker Build, Push & Update Manifests
33

44
on:
55
workflow_dispatch:

.github/workflows/docker-build-push.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# .github/workflows/docker-build-push.yaml
2-
name: App2 Docker Build & Manifest Update
2+
name: FluxCD Demo | App2 Docker Build & Manifest Update
33

44
on:
55
workflow_dispatch:

.github/workflows/echo-pod.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# .github/workflows/docker-build-push.yaml
2+
name: Echo-Pod | Docker Build & Push
3+
# This workflow builds and pushes a Docker image for the Echo-Pod application
4+
# and updates the Kubernetes manifests with the new image version.
5+
# It is triggered on workflow dispatch or when changes are made to the specified paths.
6+
# The workflow calculates the new version based on the latest version in Docker Hub
7+
# and the specified bump type (major, minor, or patch).
8+
# The new version is then used to build and push the Docker image,
9+
10+
on:
11+
workflow_dispatch:
12+
inputs:
13+
bump-type:
14+
description: 'Version bump type'
15+
required: true
16+
default: 'minor'
17+
type: choice
18+
options:
19+
- major
20+
- minor
21+
- patch
22+
push:
23+
branches:
24+
- main
25+
- dev
26+
paths:
27+
- 'dockerfiles/echo-pod/**'
28+
- '.github/workflows/echo-pod.yaml'
29+
30+
jobs:
31+
version-calculator:
32+
runs-on: ubuntu-latest
33+
outputs:
34+
new-version: ${{ steps.get-version.outputs.NEW_VERSION }}
35+
steps:
36+
- name: Get latest version from Docker Hub
37+
id: get-version
38+
run: |
39+
# Get auth token if needed (for private repos)
40+
# TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:anvesh35/echo-pod-name:pull" | jq -r .token)
41+
42+
# Get all tags
43+
TAGS=$(curl -s "https://hub.docker.com/v2/repositories/anvesh35/echo-pod-name/tags/?page_size=100" | jq -r '.results[].name')
44+
45+
# Filter and sort semantic versions
46+
LATEST=$(echo "$TAGS" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)
47+
48+
# Set default if no versions found
49+
if [ -z "$LATEST" ]; then
50+
LATEST="v0.0.0"
51+
fi
52+
53+
# Remove 'v' prefix and split version
54+
VERSION=${LATEST#v}
55+
IFS=. read MAJOR MINOR PATCH <<<"$VERSION"
56+
57+
# Determine bump type
58+
case "${{ inputs.bump-type || 'minor' }}" in
59+
major) MAJOR=$((MAJOR+1)); MINOR=0; PATCH=0 ;;
60+
minor) MINOR=$((MINOR+1)); PATCH=0 ;;
61+
patch) PATCH=$((PATCH+1)) ;;
62+
esac
63+
64+
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
65+
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
66+
67+
build-push-update:
68+
needs: version-calculator
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v3
73+
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v2
76+
77+
- name: Login to Docker Hub
78+
uses: docker/login-action@v2
79+
with:
80+
username: ${{ secrets.DOCKERHUB_USERNAME }}
81+
password: ${{ secrets.DOCKERHUB_TOKEN }}
82+
83+
- name: Build and push Docker image
84+
uses: docker/build-push-action@v4
85+
with:
86+
context: fluxcd/repos/app2/src/
87+
tags: |
88+
anvesh35/echo-pod-name:${{ needs.version-calculator.outputs.new-version }}
89+
anvesh35/echo-pod-name:latest
90+
push: true

.github/workflows/update_readme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update README with Kubernetes Blogs
1+
name: Medium | Update README with Kubernetes Blogs
22

33
on:
44
schedule:

0 commit comments

Comments
 (0)