Skip to content

Commit 18a4135

Browse files
Merge pull request #44 from anveshmuppeda/dev
Adding FluxCD Source Code
2 parents e526ee2 + 10edd5d commit 18a4135

29 files changed

+29827
-10
lines changed

.github/WorkFlow.MD

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,56 @@ To let GitHub Actions run this script daily and push changes, you need:
7272

7373
---
7474

75-
With this in place, every day at 4 AM UTC your workflow will fetch new Kubernetes posts, update the table in your README, and push the changes—keeping your blog list always up‑to‑date!
75+
With this in place, every day at 4 AM UTC your workflow will fetch new Kubernetes posts, update the table in your README, and push the changes—keeping your blog list always up‑to‑date!
76+
77+
78+
---
79+
80+
# Docker Build, Push, and Update
81+
82+
## CI/CD Workflow Steps
83+
84+
1. **Trigger Conditions**:
85+
- Runs when code is pushed to `main` or `fluxcd` branches
86+
- Also runs when new version tags (`v*`) are created
87+
88+
2. **Build Process**:
89+
- Checks out the repository code
90+
- Determines version:
91+
- Uses tag name for version tags (e.g., `v1.0.0`)
92+
- Uses first 8 characters of commit SHA for branch pushes
93+
- Builds Docker image from:
94+
```
95+
fluxcd/repos/app1/src/Dockerfile
96+
```
97+
- Tags image with format: `anvesh35/fluxcd-demo-app1:<version>`
98+
- Pushes image to Docker Hub
99+
100+
3. **Manifest Update**:
101+
- Updates deployment YAML with new image tag:
102+
```
103+
fluxcd/repos/app1/deploy/app1-deployment.yaml
104+
```
105+
- Commits the change to `fluxcd` branch with message:
106+
```
107+
"Update image to <version>"
108+
```
109+
110+
4. **Required Setup**:
111+
- Repository secrets needed:
112+
- `DOCKERHUB_USERNAME` - Your Docker Hub username
113+
- `DOCKERHUB_TOKEN` - Docker Hub access token
114+
- Repository permissions:
115+
- GitHub Actions must have write permissions
116+
- Branch protection rules must allow Actions to push to `fluxcd` branch
117+
118+
5. **Directory Structure**:
119+
```
120+
/fluxcd/repos/app1/
121+
├── src/
122+
│ └── Dockerfile # Source Dockerfile
123+
└── deploy/
124+
└── app1-deployment.yaml # Deployment manifest
125+
```
126+
127+
This workflow automatically keeps your deployment manifests synchronized with your built images, pushing all changes to the `fluxcd` branch where Flux can detect and apply them.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# .github/workflows/docker-build-push-update.yaml
2+
name: App1 Docker Build, Push & Update Manifests
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- fluxcd
9+
paths:
10+
- 'fluxcd/repos/app1/src/**'
11+
- '.github/workflows/docker-build-push-update.yaml'
12+
13+
jobs:
14+
build-push-update:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code (with all branches)
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
ref: ${{ github.ref }}
22+
23+
- name: Prepare version
24+
id: prep
25+
run: |
26+
if [[ $GITHUB_REF == refs/tags/* ]]; then
27+
VERSION=${GITHUB_REF#refs/tags/}
28+
BUILD_IMAGE=true
29+
else
30+
VERSION=${GITHUB_SHA::8}
31+
BUILD_IMAGE=true
32+
fi
33+
echo "VERSION=$VERSION" >> $GITHUB_ENV
34+
echo "IMAGE=anvesh35/fluxcd-demo-app1:$VERSION" >> $GITHUB_ENV
35+
echo "BUILD_IMAGE=$BUILD_IMAGE" >> $GITHUB_ENV
36+
37+
- name: Set up Docker Buildx
38+
if: env.BUILD_IMAGE == 'true'
39+
uses: docker/setup-buildx-action@v2
40+
41+
- name: Login to Docker Hub
42+
if: env.BUILD_IMAGE == 'true'
43+
uses: docker/login-action@v2
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
48+
- name: Build and push Docker image
49+
if: env.BUILD_IMAGE == 'true'
50+
uses: docker/build-push-action@v4
51+
with:
52+
context: fluxcd/repos/app1/src/
53+
file: fluxcd/repos/app1/src/Dockerfile
54+
push: true
55+
tags: ${{ env.IMAGE }}
56+
57+
- name: Update Kubernetes manifests
58+
run: |
59+
sed -i "s|image: anvesh35/fluxcd-demo-app1:.*|image: ${{ env.IMAGE }}|" fluxcd/repos/app1/deploy/app1-deployment.yaml
60+
git config user.name "Fluxcdbot CI"
61+
git config user.email "fluxcdbot@users.noreply.github.com"
62+
63+
- name: Commit and push changes
64+
uses: EndBug/add-and-commit@v7
65+
with:
66+
add: 'fluxcd/repos/app1/deploy/app1-deployment.yaml'
67+
message: "Update image to ${{ env.VERSION }}"
68+
signoff: true
69+
push: true
70+
branch: fluxcd
71+
author_name: "Fluxcdbot CI"
72+
author_email: "fluxcdbot@users.noreply.github.com"
73+
#token: ${{ secrets.PR_PAT_TOKEN }}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# .github/workflows/docker-build-push.yaml
2+
name: App2 Docker Build & Manifest Update
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
bump-type:
8+
description: 'Version bump type'
9+
required: true
10+
default: 'minor'
11+
type: choice
12+
options:
13+
- major
14+
- minor
15+
- patch
16+
push:
17+
branches:
18+
- main
19+
- fluxcd
20+
paths:
21+
- 'fluxcd/repos/app2/src/**'
22+
- '.github/workflows/docker-build-push.yaml'
23+
24+
jobs:
25+
version-calculator:
26+
runs-on: ubuntu-latest
27+
outputs:
28+
new-version: ${{ steps.get-version.outputs.NEW_VERSION }}
29+
steps:
30+
- name: Get latest version from Docker Hub
31+
id: get-version
32+
run: |
33+
# Get auth token if needed (for private repos)
34+
# TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:anvesh35/fluxcd-demo-app2:pull" | jq -r .token)
35+
36+
# Get all tags
37+
TAGS=$(curl -s "https://hub.docker.com/v2/repositories/anvesh35/fluxcd-demo-app2/tags/?page_size=100" | jq -r '.results[].name')
38+
39+
# Filter and sort semantic versions
40+
LATEST=$(echo "$TAGS" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1)
41+
42+
# Set default if no versions found
43+
if [ -z "$LATEST" ]; then
44+
LATEST="v0.0.0"
45+
fi
46+
47+
# Remove 'v' prefix and split version
48+
VERSION=${LATEST#v}
49+
IFS=. read MAJOR MINOR PATCH <<<"$VERSION"
50+
51+
# Determine bump type
52+
case "${{ inputs.bump-type || 'minor' }}" in
53+
major) MAJOR=$((MAJOR+1)); MINOR=0; PATCH=0 ;;
54+
minor) MINOR=$((MINOR+1)); PATCH=0 ;;
55+
patch) PATCH=$((PATCH+1)) ;;
56+
esac
57+
58+
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
59+
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
60+
61+
build-push-update:
62+
needs: version-calculator
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v3
67+
68+
- name: Set up Docker Buildx
69+
uses: docker/setup-buildx-action@v2
70+
71+
- name: Login to Docker Hub
72+
uses: docker/login-action@v2
73+
with:
74+
username: ${{ secrets.DOCKERHUB_USERNAME }}
75+
password: ${{ secrets.DOCKERHUB_TOKEN }}
76+
77+
- name: Build and push Docker image
78+
uses: docker/build-push-action@v4
79+
with:
80+
context: fluxcd/repos/app2/src/
81+
tags: |
82+
anvesh35/fluxcd-demo-app2:${{ needs.version-calculator.outputs.new-version }}
83+
anvesh35/fluxcd-demo-app2:latest
84+
push: true

.github/workflows/update_readme.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,25 @@ jobs:
3131
# cd ./.github/scripts/
3232
python ./.github/scripts/update_readme.py
3333
34+
# - name: Commit and push changes
35+
# env:
36+
# GITHUB_TOKEN: ${{ secrets.PR_PAT_TOKEN }}
37+
# run: |
38+
# # cd ./.github/scripts/
39+
# git config --global user.name "GitHub Actions"
40+
# git config --global user.email "actions@users.noreply.github.com"
41+
# git add README.md
42+
# git commit -m "Update README with latest Kubernetes blogs"
43+
# git push origin dev
44+
3445
- name: Commit and push changes
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.PR_PAT_TOKEN }}
37-
run: |
38-
# cd ./.github/scripts/
39-
git config --global user.name "Kubernetes Bot"
40-
git config --global user.email "kubernetes-bot@anveshmuppeda.com"
41-
git add README.md
42-
git commit -m "Update README with latest Kubernetes blogs"
43-
git push origin dev
46+
uses: EndBug/add-and-commit@v7
47+
with:
48+
add: 'README.md'
49+
message: "Update README with latest Kubernetes blogs"
50+
signoff: true
51+
push: true
52+
branch: dev
53+
author_name: "Kubernetes CI"
54+
author_email: "k8s-ci-robot@users.noreply.github.com"
55+
#token: ${{ secrets.PR_PAT_TOKEN }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Kubernetes, also known as K8s, is an open-source container orchestration platfor
7676

7777

7878

79+
80+
7981
<!-- BLOG-POST-LIST:END -->
8082

8183
## Architecture

0 commit comments

Comments
 (0)