-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add production, test, and development application properties, edit wo…
…rkflow
- Loading branch information
1 parent
fc52f40
commit d862182
Showing
6 changed files
with
137 additions
and
57 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 |
---|---|---|
@@ -1,45 +1,121 @@ | ||
name: Continous Deployment (CD) | ||
name: Java CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Cloud Run Deployment | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup GCP Service Account | ||
uses: GoogleCloudPlatform/github-actions/setup-gcloud@v2 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
version: "latest" | ||
service_account_email: ${{ secrets.GCP_SA_EMAIL }} | ||
service_account_key: ${{ secrets.GCP_SA_KEY }} | ||
export_default_credentials: true | ||
distribution: "temurin" | ||
java-version: "21" | ||
cache: "gradle" | ||
|
||
- name: Configure Docker | ||
- name: Cache Gradle dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Make gradlew executable | ||
run: chmod +x ./gradlew | ||
- name: Build with Gradle | ||
run: | | ||
gcloud auth configure-docker | ||
./gradlew assemble | ||
# (Optional) Add steps for running tests and generating reports | ||
|
||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: java-app | ||
path: build/libs/*.jar | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: "temurin" | ||
java-version: "21" | ||
cache: "gradle" | ||
- name: Make gradlew executable | ||
run: chmod +x ./gradlew | ||
- name: Cache Gradle dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Test with Gradle | ||
run: | | ||
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/heymart-auth:latest . | ||
./gradlew check --info --stacktrace | ||
./gradlew test | ||
./gradlew jacocoTestReport | ||
# (Optional) Add steps for generating coverage report and other post-test tasks | ||
|
||
- name: Push | ||
publish: | ||
name: Publish Docker Image | ||
runs-on: ubuntu-latest | ||
needs: test | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: check directory | ||
run: ls -al | ||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: java-app | ||
- name: check directory | ||
run: ls -al | ||
- name: Login to Docker Hub | ||
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.REGISTRY_USER }} --password-stdin docker.io | ||
- name: Set Docker BuildKit | ||
run: export DOCKER_BUILDKIT=1 | ||
- name: Build Docker Image | ||
run: | | ||
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/heymart-auth:latest | ||
docker build --build-arg PRODUCTION=${{ secrets.PRODUCTION }} --build-arg JDBC_DATABASE_PASSWORD=${{ secrets.JDBC_DATABASE_PASSWORD }} --build-arg JDBC_DATABASE_URL=${{ secrets.JDBC_DATABASE_URL }} --build-arg JDBC_DATABASE_USERNAME=${{ secrets.JDBC_DATABASE_USERNAME }} -t ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }} . | ||
docker push ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }} | ||
deploy: | ||
name: Deploy to GCP | ||
runs-on: ubuntu-latest | ||
needs: publish | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install SSH client | ||
run: sudo apt-get install openssh-client | ||
|
||
- name: create ssh key | ||
run: echo "${{ secrets.SSH_KEY }}" > ssh-key.pem | ||
|
||
- name: Deploy | ||
- name: update permission | ||
run: chmod 400 ssh-key.pem | ||
- name: Deploy to GCP | ||
run: | | ||
gcloud run deploy heymart-auth \ | ||
--region europe-west1 \ | ||
--image gcr.io/${{ secrets.GCP_PROJECT_ID }}/heymart-auth \ | ||
--platform managed \ | ||
--allow-unauthenticated \ | ||
--project ${{ secrets.GCP_PROJECT_ID }} \ | ||
--set-env-vars=PG_HOST=${{ secrets.PG_HOST }} \ | ||
--set-env-vars=PG_DB=${{ secrets.PG_USER }} \ | ||
--set-env-vars=PG_USER=${{ secrets.PG_PASS }} | ||
ssh -o StrictHostKeyChecking=no -i ssh-key.pem ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_STATIC_IP }} " | ||
sudo docker container rm -f ${{ secrets.CONTAINER_NAME }} || true && | ||
sudo docker image rm -f ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }} || true && | ||
sudo docker run --name ${{ secrets.CONTAINER_NAME }} -d -p 80:8080 ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }}" |
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,23 +1,16 @@ | ||
# Use the official maven/Java 8 image to create a build artifact. | ||
# https://hub.docker.com/_/maven | ||
FROM maven:3.5-jdk-8-alpine as builder | ||
FROM gradle:jdk21-alpine | ||
ARG PRODUCTION | ||
ARG JDBC_DATABASE_PASSWORD | ||
ARG JDBC_DATABASE_URL | ||
ARG JDBC_DATABASE_USERNAME | ||
|
||
# Copy local code to the container image. | ||
WORKDIR /app | ||
COPY pom.xml . | ||
COPY src ./src | ||
|
||
# Build a release artifact. | ||
RUN mvn package -DskipTests | ||
|
||
# Use AdoptOpenJDK for base image. | ||
# It's important to use OpenJDK 8u191 or above that has container support enabled. | ||
# https://hub.docker.com/r/adoptopenjdk/openjdk8 | ||
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | ||
FROM adoptopenjdk/openjdk8:jdk8u202-b08-alpine-slim | ||
ENV PRODUCTION ${PRODUCTION} | ||
ENV JDBC_DATABASE_PASSWORD ${JDBC_DATABASE_PASSWORD} | ||
ENV JDBC_DATABASE_URL ${JDBC_DATABASE_URL} | ||
ENV JDBC_DATABASE_USERNAME ${JDBC_DATABASE_USERNAME} | ||
|
||
# Copy the jar to the production image from the builder stage. | ||
COPY --from=builder /app/target/review-*.jar /review.jar | ||
|
||
# Run the web service on container startup. | ||
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/review.jar"] | ||
WORKDIR /app | ||
COPY ./review-0.0.1-SNAPSHOT.jar /app | ||
RUN ls -la | ||
EXPOSE 8080 | ||
CMD ["java","-jar","review-0.0.1-SNAPSHOT.jar"] |
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.datasource.url=jdbc:postgresql://aws-0-ap-southeast-1.pooler.supabase.com:5432/postgres | ||
spring.datasource.username=postgres | ||
spring.datasource.password=postgres | ||
spring.jpa.hibernate.ddl-auto=create-drop | ||
spring.jpa.show-sql=true | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.properties.hibernate.format_sql=true |
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,6 @@ | ||
spring.datasource.url=${JDBC_DATABASE_URL} | ||
spring.datasource.username=${JDBC_DATABASE_USERNAME} | ||
spring.datasource.password=${JDBC_DATABASE_PASSWORD} | ||
spring.jpa.hibernate.ddl-auto=update | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.properties.hibernate.format_sql=true |
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.datasource.url=jdbc:postgresql://aws-0-ap-southeast-1.pooler.supabase.com:5432/postgres | ||
spring.datasource.username=postgres | ||
spring.datasource.password=postgres | ||
spring.jpa.hibernate.ddl-auto=create | ||
spring.jpa.show-sql=true | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.properties.hibernate.format_sql=true |
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,11 +1,2 @@ | ||
spring.application.name=review | ||
spring.config.import=optional:file:.env[.properties] | ||
# Database | ||
spring.datasource.url=${PG_HOST} | ||
spring.datasource.username=${PG_USER} | ||
spring.datasource.password=${PG_PASS} | ||
server.port=${PORT} | ||
# Hibernate / JPA | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.hibernate.ddl-auto=update | ||
spring.jpa.show-sql=true | ||
spring.profiles.active=${PRODUCTION:dev} |