-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Auction server CI/CD with gradle | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build-docker-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Build with Gradle | ||
run: ./gradlew build | ||
|
||
- name: Build docker image | ||
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/auction-service:latest -f Dockerfile . | ||
|
||
- name: login Docker | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Push docker hub | ||
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/auction-service:latest | ||
|
||
run-docker-image-on-ec2: | ||
needs: build-docker-image | ||
runs-on: self-hosted | ||
|
||
steps: | ||
- name: Pull image from docker hub | ||
run: | | ||
sudo docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password ${{ secrets.DOCKERHUB_PASSWORD }} | ||
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/auction-service:latest | ||
- name: Check if container is running | ||
id: check-container | ||
run: | | ||
if sudo docker ps -a | grep -q auction-service; then | ||
echo "auction-service-running=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "auction-service-running=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Stop and remove container | ||
if: steps.check-container.outputs.eureka-server-running == 'true' | ||
run: sudo docker stop auction-service | ||
|
||
- name: Run new docker container | ||
run: sudo docker run -d --name auction-service --rm -p 9001:9001 --net cheonma-network ${{ secrets.DOCKERHUB_USERNAME }}/auction-service:latest | ||
|
||
- name: Delete old docker image | ||
run: sudo docker system prune -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,4 @@ out/ | |
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
*.yml | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
FROM openjdk:17-slim | ||
CMD ["./gradlew", "clean", "build"] | ||
FROM bellsoft/liberica-openjdk-alpine:17 as build | ||
WORKDIR /workspace/app | ||
|
||
# Copy the built JAR file | ||
COPY build/libs/*.jar . | ||
|
||
# Unpack the built application | ||
RUN mkdir -p target/extracted | ||
RUN java -Djarmode=layertools -jar *.jar extract --destination target/extracted | ||
|
||
FROM bellsoft/liberica-openjdk-alpine:17 | ||
VOLUME /tmp | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
EXPOSE 9001 | ||
ENTRYPOINT ["java","-jar","/app.jar"] | ||
ARG EXTRACTED=/workspace/app/target/extracted | ||
|
||
# Copy over the unpacked application | ||
COPY --from=build ${EXTRACTED}/dependencies/ ./ | ||
COPY --from=build ${EXTRACTED}/spring-boot-loader/ ./ | ||
COPY --from=build ${EXTRACTED}/snapshot-dependencies/ ./ | ||
COPY --from=build ${EXTRACTED}/application/ ./ | ||
|
||
ENTRYPOINT ["java","-Dspring.profiles.active=dev","org.springframework.boot.loader.JarLauncher"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
spring: | ||
application: | ||
name: auction-service | ||
profiles: | ||
active: dev | ||
config: | ||
import: optional:configserver:http://43.203.131.185:8071 |