Skip to content

Commit 31dfe8d

Browse files
committed
feat(ci-cd-k8s): added separate pipelines for develop, feature and release
1 parent 9cfa974 commit 31dfe8d

File tree

3 files changed

+131
-10
lines changed

3 files changed

+131
-10
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Deploy to Local Kubernetes
2+
3+
on:
4+
push:
5+
branches:
6+
- feature/*
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '21'
20+
distribution: 'temurin'
21+
22+
- name: Build with Maven
23+
run: mvn clean package -DskipTests
24+
25+
- name: Log in to GitHub Container Registry
26+
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
27+
28+
- name: Build and Push Docker Image
29+
run: |
30+
for service in user-service order-service product-service; do
31+
docker build -t ghcr.io/${{ github.repository_owner }}/$service:latest ./$service
32+
docker push ghcr.io/${{ github.repository_owner }}/$service:latest
33+
done
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build and Deploy to Local Kubernetes
33
on:
44
push:
55
branches:
6-
- feature/ci_cd_k8s_support
6+
- feature/*
77

88
jobs:
99
build-and-deploy:
@@ -22,15 +22,15 @@ jobs:
2222
- name: Build with Maven
2323
run: mvn clean package -DskipTests
2424

25-
- name: Log in to GitHub Container Registry
26-
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
27-
28-
- name: Build and Push Docker Image
29-
run: |
30-
for service in user-service order-service product-service; do
31-
docker build -t ghcr.io/${{ github.repository_owner }}/$service:latest ./$service
32-
docker push ghcr.io/${{ github.repository_owner }}/$service:latest
33-
done
25+
# - name: Log in to GitHub Container Registry
26+
# run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
27+
#
28+
# - name: Build and Push Docker Image
29+
# run: |
30+
# for service in user-service order-service product-service; do
31+
# docker build -t ghcr.io/${{ github.repository_owner }}/$service:latest ./$service
32+
# docker push ghcr.io/${{ github.repository_owner }}/$service:latest
33+
# done
3434
# - name: Set up kubectl
3535
# uses: azure/setup-kubectl@v3
3636
# with:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Release Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- 'release/**'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0 # Needed to push tags & branches
17+
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v3
20+
with:
21+
java-version: '21'
22+
distribution: 'temurin'
23+
24+
- name: Extract release version from branch name
25+
id: vars
26+
run: |
27+
# Assuming branch name like release/1.2.3
28+
echo "RELEASE_VERSION=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_OUTPUT
29+
30+
- name: Build with Maven
31+
run: mvn clean package -DskipTests
32+
33+
- name: Create and push Git tag for release
34+
env:
35+
RELEASE_VERSION: ${{ steps.vars.outputs.RELEASE_VERSION }}
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
git config user.name "github-actions[bot]"
39+
git config user.email "github-actions[bot]@users.noreply.github.com"
40+
git tag -a "v$RELEASE_VERSION" -m "Release $RELEASE_VERSION"
41+
git push origin "v$RELEASE_VERSION"
42+
43+
- name: Checkout master branch
44+
run: git checkout master
45+
46+
- name: Update master branch to latest release tag
47+
env:
48+
RELEASE_VERSION: ${{ steps.vars.outputs.RELEASE_VERSION }}
49+
run: |
50+
git reset --hard "v$RELEASE_VERSION"
51+
git push origin master --force
52+
53+
- name: Checkout develop branch
54+
run: git checkout develop
55+
56+
- name: Bump develop version to next SNAPSHOT
57+
env:
58+
RELEASE_VERSION: ${{ steps.vars.outputs.RELEASE_VERSION }}
59+
run: |
60+
# Extract major.minor.patch, then increment patch + add SNAPSHOT
61+
IFS='.' read -r major minor patch <<< "${RELEASE_VERSION}"
62+
next_patch=$((patch + 1))
63+
next_snapshot="${major}.${minor}.${next_patch}-SNAPSHOT"
64+
65+
echo "Next develop version: $next_snapshot"
66+
67+
# Update version in pom.xml or your version file
68+
mvn versions:set -DnewVersion=$next_snapshot
69+
mvn versions:commit
70+
71+
git config user.name "github-actions[bot]"
72+
git config user.email "github-actions[bot]@users.noreply.github.com"
73+
74+
git add pom.xml
75+
git commit -m "Bump develop version to $next_snapshot"
76+
git push origin develop
77+
78+
- name: Build and push Docker images
79+
env:
80+
RELEASE_VERSION: ${{ steps.vars.outputs.RELEASE_VERSION }}
81+
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
82+
run: |
83+
echo "${GHCR_TOKEN}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
84+
85+
for service in user-service order-service product-service; do
86+
docker build -t ghcr.io/${{ github.repository_owner }}/$service:$RELEASE_VERSION ./$service
87+
docker push ghcr.io/${{ github.repository_owner }}/$service:$RELEASE_VERSION
88+
done

0 commit comments

Comments
 (0)