Skip to content

Commit 7b9630f

Browse files
Commit all changes for K and Helm
0 parents  commit 7b9630f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1651
-0
lines changed

.github/workflows/helm-ci.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# name: Helm CI - Build and Update Values.yaml
2+
3+
# on:
4+
# push:
5+
# branches:
6+
# - main
7+
8+
# jobs:
9+
# build-and-push:
10+
# name: Build and Push Docker Image
11+
# runs-on: ubuntu-latest
12+
13+
# outputs:
14+
# image-tag: ${{ steps.meta.outputs.image-tag }}
15+
16+
# env:
17+
# IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
18+
19+
# steps:
20+
# - name: Checkout code
21+
# uses: actions/checkout@v4
22+
23+
# - name: Set up JDK 17
24+
# uses: actions/setup-java@v4
25+
# with:
26+
# distribution: 'temurin'
27+
# java-version: '17'
28+
29+
# - name: Build Spring Boot App
30+
# working-directory: ./app
31+
# run: ./mvnw clean package -DskipTests
32+
33+
# - name: Set up Docker Buildx
34+
# uses: docker/setup-buildx-action@v3
35+
36+
# - name: Login to DockerHub
37+
# uses: docker/login-action@v3
38+
# with:
39+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
40+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
41+
42+
# - name: Build and Push Docker Image
43+
# id: meta
44+
# run: |
45+
# COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
46+
# IMAGE_TAG="main-${COMMIT_SHA}"
47+
48+
# echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
49+
# echo "::set-output name=image-tag::$IMAGE_TAG"
50+
51+
# docker build -t $IMAGE_NAME:$IMAGE_TAG ./app
52+
# docker push $IMAGE_NAME:$IMAGE_TAG
53+
54+
# update-helm-values:
55+
# name: Update Helm Values
56+
# needs: build-and-push
57+
# runs-on: ubuntu-latest
58+
59+
# env:
60+
# IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
61+
# IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
62+
63+
# steps:
64+
# - name: Checkout code
65+
# uses: actions/checkout@v4
66+
67+
# - name: Update image.tag in values.yaml
68+
# run: |
69+
# FILE="helm/springboot-postgres-prod/values.yaml"
70+
# echo "Updating $FILE with image tag $IMAGE_TAG"
71+
72+
# # Replace the image tag line
73+
# sed -i.bak -E "s|tag:.*|tag: \"$IMAGE_TAG\"|" "$FILE"
74+
75+
# - name: Commit and Push changes
76+
# run: |
77+
# git config --global user.name "github-actions"
78+
# git config --global user.email "github-actions@github.com"
79+
80+
# git add helm/springboot-postgres-prod/values.yaml
81+
# git commit -m "Update Helm image tag to $IMAGE_TAG"
82+
# git push
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Kustomize CI - Build and Push
2+
3+
on:
4+
push:
5+
branches:
6+
- feature/**
7+
- development
8+
9+
jobs:
10+
build-and-push:
11+
name: Build and Push Docker Image
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up JDK 17
22+
uses: actions/setup-java@v4
23+
with:
24+
distribution: 'temurin'
25+
java-version: '17'
26+
27+
- name: Build Spring Boot App
28+
working-directory: ./app
29+
run: ./mvnw clean package -DskipTests
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to DockerHub
35+
uses: docker/login-action@v3
36+
with:
37+
username: ${{ secrets.DOCKERHUB_USERNAME }}
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
40+
- name: Build and Push Docker Image
41+
run: |
42+
COMMIT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
43+
BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '-')
44+
TAG="${BRANCH}-${COMMIT_SHA}"
45+
46+
docker build -t $IMAGE_NAME:$TAG ./app
47+
docker push $IMAGE_NAME:$TAG
48+
49+
update-kustomize:
50+
name: Update Kustomize Overlay
51+
needs: build-and-push
52+
runs-on: ubuntu-latest
53+
54+
env:
55+
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/springboot-postgres
56+
IMAGE_TAG: ${{ needs.build-and-push.outputs.image-tag }}
57+
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
62+
- name: Update image tag in dev overlay
63+
run: |
64+
FILE="kustomize/overlays/dev/patch-deployment-image.yaml"
65+
66+
echo "Updating $FILE with image: $IMAGE_NAME:$IMAGE_TAG"
67+
68+
sed -i.bak -E "s|image:.*|image: ${IMAGE_NAME}:${IMAGE_TAG}|" "$FILE"
69+
70+
- name: Commit and push changes
71+
run: |
72+
git config --global user.name ${{ secrets.GIT_USER_EMAIL }}
73+
git config --global user.email ${{ secrets.GIT_USER_NAME }}
74+
75+
git add kustomize/overlays/dev/patch-deployment-image.yaml
76+
git commit -m "Update image tag to $IMAGE_TAG"
77+
git push

.gitignore

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# General
2+
.DS_Store
3+
*.log
4+
*.tmp
5+
*.swp
6+
*.bak
7+
*.old
8+
*.orig
9+
10+
# Node.js (if applicable)
11+
node_modules/
12+
npm-debug.log*
13+
yarn-debug.log*
14+
yarn-error.log*
15+
16+
# Python (if applicable)
17+
__pycache__/
18+
*.py[cod]
19+
*.pyo
20+
21+
# Java (if applicable)
22+
*.class
23+
*.jar
24+
*.war
25+
*.ear
26+
*.iml
27+
*.project
28+
*.classpath
29+
target/
30+
31+
# Terraform
32+
*.tfstate
33+
*.tfstate.*
34+
.terraform/
35+
.terraform.lock.hcl
36+
37+
# Kubernetes
38+
39+
# Helm
40+
41+
42+
# AWS Credentials
43+
aws-credentials.json
44+
*.pem
45+
*.key
46+
47+
# IDEs and Editors
48+
.idea/
49+
.vscode/
50+
*.code-workspace
51+
52+
# MacOS
53+
.DS_Store
54+
55+
# Logs and temporary files
56+
*.log
57+
*.out
58+
*.tmp
59+
60+
# Ignore sensitive files
61+
venv/
62+
.env
63+
.env.*
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

app/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -------- Stage 1: Build --------
2+
FROM maven:3.9.6-eclipse-temurin-17 AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy only pom.xml first and download dependencies
7+
COPY pom.xml .
8+
RUN mvn dependency:go-offline
9+
10+
# Now copy rest of the code and package
11+
COPY . .
12+
RUN mvn clean package -DskipTests
13+
14+
# -------- Stage 2: Runtime --------
15+
FROM eclipse-temurin:17-jdk
16+
17+
WORKDIR /app
18+
19+
# Copy built JAR from builder stage
20+
COPY --from=builder /app/target/springboot-postgres-0.0.1-SNAPSHOT.jar app.jar
21+
22+
EXPOSE 8080
23+
CMD ["java", "-jar", "app.jar"]

app/docker-compose.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: '3.8'
2+
3+
services:
4+
postgres:
5+
image: postgres:15
6+
container_name: postgres
7+
environment:
8+
POSTGRES_DB: mydb
9+
POSTGRES_USER: postgres
10+
POSTGRES_PASSWORD: mysecretpassword
11+
ports:
12+
- "5432:5432"
13+
14+
springboot:
15+
image: sugesh23/springboot-postgres:latest
16+
depends_on:
17+
- postgres
18+
ports:
19+
- "8081:80"
20+
environment:
21+
DB_HOST: postgres
22+
DB_PORT: 5432
23+
POSTGRES_DB: mydb
24+
POSTGRES_USER: postgres
25+
POSTGRES_PASSWORD: mysecretpassword

0 commit comments

Comments
 (0)