Skip to content

Commit

Permalink
#145 - Setup CI/CD 4️⃣ 🫸🌀✏️📗 :octocat:🐧🐳
Browse files Browse the repository at this point in the history
  • Loading branch information
hendisantika committed Mar 13, 2024
1 parent c36cd7a commit db9c1a2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/samples/app-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
file: Dockerfile2
push: true
labels: ${{ steps.meta.outputs.labels }}
# tags: hendisantika/bmi:${{ steps.meta.outputs.tags }}
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/deploy_via_ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
aws-region: ${{ secrets.AWS_REGION }}

- name: install ssh keys
# check this thread to understand why its needed:
Expand All @@ -86,16 +86,6 @@ jobs:
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
# with:
# registry-type: private


# - name: connect and pull
# env:
# ECR_REGISTRY: ${{ steps.login-pf-aws-ecr.outputs.registry }}
# ECR_REPOSITORY: ${{secrets.AWS_ECR_REPO}}
# IMAGE_TAG: ${{ github.run_number }}
# run: ssh ${{ secrets.SSH_USER }}@${{ secrets.HOST }} "cd /var/www/DALIM && export ECR_PW=`aws ecr get-login-password --region ap-southeast1 --output text | docker login --username AWS --password-stdin` && docker pull $ECR_REGISTRY/$ECR_REPOSITORY:latest && docker compose pull && docker compose up -d && exit"

- name: Docker pull & run from github
uses: appleboy/ssh-action@master
Expand Down
44 changes: 13 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
FROM maven:3.9.6-eclipse-temurin-21-alpine AS build
FROM bellsoft/liberica-runtime-container:jdk-21-stream-musl as builder
LABEL authors="hendisantika"

RUN mkdir /project

COPY . /project

# Passed from Github Actions
ARG GIT_VERSION_TAG=unspecified
ARG GIT_COMMIT_MESSAGE=unspecified
ARG GIT_VERSION_HASH=unspecified

WORKDIR /project

# You can read these files for the information in your application
RUN echo $GIT_VERSION_TAG > GIT_VERSION_TAG.txt
RUN echo $GIT_COMMIT_MESSAGE > GIT_COMMIT_MESSAGE.txt
RUN echo $GIT_VERSION_HASH > GIT_VERSION_HASH.txt

RUN mvn clean package

#FROM adoptopenjdk/openjdk21:eclipse-temurin-21-alpine
#FROM bellsoft/liberica-openjdk-debian:21
#FROM openjdk:21-slim
FROM amazoncorretto:21-alpine-jdk
LABEL maintainer="[email protected]"

RUN mkdir /app

RUN addgroup -g 1001 -S hendigroup

RUN adduser -S hendi -u 1001

COPY --from=build /project/target/HikariCP-0.0.1.jar /app/HikariCP.jar

WORKDIR /app

RUN chown -R hendi:hendigroup /app

CMD java $JAVA_OPTS -jar HikariCP.jar
RUN cd /project/HikariCP && ./mvnw clean package
#ADD hikaricp /home/myapp/hikaricp
#RUN cd hikaricp && \
RUN ./mvnw clean package
FROM bellsoft/alpaquita-linux-base:stream-musl-230404
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
VOLUME /tmp
WORKDIR /home/myapp
COPY --from=builder /project/HikariCP/target .
EXPOSE 9000
CMD ["java", "-jar", "HikariCP-0.0.1.jar"]
19 changes: 19 additions & 0 deletions Dockerfile1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#FROM eclipse-temurin:21-jre-alpine
FROM maven:3.9.6-eclipse-temurin-21-alpine AS build

## create a nonroot user and group
RUN addgroup -S spring && adduser -S spring -G spring

## copy the spring jar
COPY target/*.jar /opt/myApp.jar

## set the nonroot user as the default user
USER spring:spring

## set the working directory
WORKDIR /opt

ENTRYPOINT ["java", "-jar", "myApp.jar"]

## expose the port to the external world
EXPOSE 9000
40 changes: 40 additions & 0 deletions Dockerfile2
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM maven:3.9.6-eclipse-temurin-21-alpine AS build
LABEL authors="hendisantika"

RUN mkdir /project

COPY . /project

# Passed from Github Actions
ARG GIT_VERSION_TAG=unspecified
ARG GIT_COMMIT_MESSAGE=unspecified
ARG GIT_VERSION_HASH=unspecified

WORKDIR /project

# You can read these files for the information in your application
RUN echo $GIT_VERSION_TAG > GIT_VERSION_TAG.txt
RUN echo $GIT_COMMIT_MESSAGE > GIT_COMMIT_MESSAGE.txt
RUN echo $GIT_VERSION_HASH > GIT_VERSION_HASH.txt

RUN mvn clean package

#FROM adoptopenjdk/openjdk21:eclipse-temurin-21-alpine
#FROM bellsoft/liberica-openjdk-debian:21
#FROM openjdk:21-slim
FROM amazoncorretto:21-alpine-jdk
LABEL maintainer="[email protected]"

RUN mkdir /app

RUN addgroup -g 1001 -S hendigroup

RUN adduser -S hendi -u 1001

COPY --from=build /project/target/HikariCP-0.0.1.jar /app/HikariCP.jar

WORKDIR /app

RUN chown -R hendi:hendigroup /app

CMD java $JAVA_OPTS -jar HikariCP.jar
8 changes: 8 additions & 0 deletions Dockerfile3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM amazoncorretto:21-alpine-jdk
LABEL maintainer="[email protected]"
VOLUME /tmp
EXPOSE 9000
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} HikariCP-0.0.1.jar
ENTRYPOINT ["java","-jar","HikariCP-0.0.1.jar"]

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.hendisantika.webapp</groupId>
<artifactId>HikariCP</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<packaging>jar</packaging>

<name>SpringBootDemoHikari</name>
<description>Demo project for Spring Boot</description>
Expand Down

0 comments on commit db9c1a2

Please sign in to comment.