Skip to content

Commit

Permalink
deploymeny and pipeline added
Browse files Browse the repository at this point in the history
  • Loading branch information
M4rc0Russ0 committed Jul 26, 2024
1 parent 546f897 commit 75b3f81
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 36 deletions.
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Subject

- Please write the development content.

## Changes Description

- Please write the main changes or the contents to be referred to in the review.

## How to test

- Please describe the prerequisites and the steps to test

## Evident for results

- Please attach images or videos to confirm the right result

## Referenced Ticket

- https://cardanofoundation.atlassian.net/browse/LOB-
67 changes: 67 additions & 0 deletions .github/workflows/build-with-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Run Tests

on:
push:
branches-ignore:
- main
workflow_dispatch:

jobs:

test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16.3
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'

- name: Test
run: |
./gradlew clean test
mutation-test:
needs: test
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'

- name: PiTest
run: |
./gradlew clean pitest
- name: Publish mutation test report to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
if: github.ref == 'refs/heads/main'
with:
BRANCH: gh-pages
folder: build/reports/pitest/
target-folder: mutation-report/
93 changes: 93 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build

on:
pull_request:
types: [ opened, synchronize ]
push:
branches:
- main
workflow_dispatch:

env:
PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }}
PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token
PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'

- name: Build
run: |
./gradlew build -x test
publish:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set extra environment and metadata
id: metadata
run: |
GIT_SHORT_COMMIT=$(git rev-parse --short "$GITHUB_SHA")
CURRENT_VERSION=$(grep '^version' gradle.properties | sed 's|.*version = \(.*\)$|\1|')
if [ ${{github.event_name}} == "pull_request" ]
then
PR_NUMBER=$(echo $GITHUB_REF | awk -F/ '{ print $3 }')
ARTIFACT_VERSION="${CURRENT_VERSION}-PR${PR_NUMBER}"
echo "ARTIFACT_VERSION=${ARTIFACT_VERSION}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
else
BRANCH=${GITHUB_REF_NAME}
SANITIZED_BRANCH=$(echo $BRANCH | sed 's|/|-|g')
echo "BRANCH=${BRANCH}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
echo "SANITIZED_BRANCH=${SANITIZED_BRANCH}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
ARTIFACT_VERSION=${CURRENT_VERSION}-${SANITIZED_BRANCH}
echo "ARTIFACT_VERSION=${ARTIFACT_VERSION}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
fi
echo "DOCKER_COMMIT_TAG=${ARTIFACT_VERSION}-${GIT_SHORT_COMMIT}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
echo "DOCKER_COMMIT_GHRUNID_TAG=${ARTIFACT_VERSION}-${GIT_SHORT_COMMIT}-${GITHUB_RUN_ID}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
echo "EARTHLY_BUILD_ARGS=DOCKER_IMAGES_EXTRA_TAGS=${ARTIFACT_VERSION}-${GIT_SHORT_COMMIT} ${ARTIFACT_VERSION}-${GIT_SHORT_COMMIT}-${GITHUB_RUN_ID}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
- name: Docker Login (private registry)
uses: docker/login-action@v2
with:
registry: ${{ env.PRIVATE_DOCKER_REGISTRY_URL }}
username: ${{ env.PRIVATE_DOCKER_REGISTRY_USER }}
password: ${{ env.PRIVATE_DOCKER_REGISTRY_PASS }}

#- name: Docker Login (hub.docker.com)
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.HUB_DOCKER_COM_USER }}
# password: ${{ secrets.HUB_DOCKER_COM_PASS }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- uses: earthly/actions-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "0.8.6"

- name: 🌍 earthly (docker build and push)
env:
EARTHLY_BUILD_ARGS: ${{ steps.metadata.outputs.EARTHLY_BUILD_ARGS }},DOCKER_REGISTRIES=${{ secrets.DOCKER_REGISTRIES }}
run: |
earthly +docker-publish --PUSH=true
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FROM openjdk:21-jdk-slim AS build
WORKDIR /app
COPY . /app
RUN ./gradlew clean build publishMavenJavaPublicationToLocalM2Repository

RUN ./gradlew clean -x test build
FROM openjdk:21-jdk-slim AS backend
WORKDIR /app
COPY --from=build /app/build/libs/*SNAPSHOT.jar /app/app.jar
FROM scratch AS m2-cache
COPY --from=build /root/.m2 /root/.m2

ENTRYPOINT ["java", "-jar", "app.jar"]
25 changes: 13 additions & 12 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
VERSION 0.8

ARG --global ALL_BUILD_TARGETS="backend"
ARG --global ALL_BUILD_TARGETS="m2-cache"

ARG --global DOCKER_IMAGE_PREFIX="cf-lob"
ARG --global DOCKER_IMAGE_PREFIX="cf-lob-platform-library"
ARG --global DOCKER_IMAGES_EXTRA_TAGS=""
ARG --global DOCKER_REGISTRIES="hub.docker.com"
ARG --global HUB_DOCKER_COM_ORG=cardanofoundation
ARG --global PUSH=false

all:
LOCALLY
Expand All @@ -28,25 +29,25 @@ docker-publish:
IF [ ! -z "$DOCKER_IMAGES_EXTRA_TAGS" ]
FOR image_tag IN $DOCKER_IMAGES_EXTRA_TAGS
IF [ "$registry" = "hub.docker.com" ]
RUN echo docker tag ${IMAGE_NAME}:latest ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${image_tag}
RUN echo docker push ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${image_tag}
RUN docker tag ${IMAGE_NAME}:latest ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${image_tag}
RUN if [ "$PUSH" = "true" ]; then docker push ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${image_tag}; fi
ELSE
RUN echo docker tag ${IMAGE_NAME}:latest ${registry}/${IMAGE_NAME}:${image_tag}
RUN echo docker push ${registry}/${IMAGE_NAME}:${image_tag}
RUN docker tag ${IMAGE_NAME}:latest ${registry}/${IMAGE_NAME}:${image_tag}
RUN if [ "$PUSH" = "true" ]; then docker push ${registry}/${IMAGE_NAME}:${image_tag}; fi
END
END
END
IF [ "$registry" = "hub.docker.com" ]
RUN echo docker tag ${IMAGE_NAME}:latest ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}
RUN echo docker push ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}
RUN docker tag ${IMAGE_NAME}:latest ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}
RUN if [ "$PUSH" = "true" ]; then docker push ${HUB_DOCKER_COM_ORG}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}; fi
ELSE
RUN echo docker tag ${IMAGE_NAME}:latest ${registry}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}
RUN echo docker push ${registry}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}
RUN docker tag ${IMAGE_NAME}:latest ${registry}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}
RUN if [ "$PUSH" = "true" ]; then docker push ${registry}/${IMAGE_NAME}:${EARTHLY_GIT_SHORT_HASH}; fi
END
END
END

backend:
m2-cache:
ARG EARTHLY_TARGET_NAME
FROM DOCKERFILE -f Dockerfile --target ${EARTHLY_TARGET_NAME} .
SAVE IMAGE ${DOCKER_IMAGE_PREFIX}-${EARTHLY_TARGET_NAME}:latest
SAVE IMAGE ${DOCKER_IMAGE_PREFIX}-${EARTHLY_TARGET_NAME}:latest
27 changes: 8 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
# volumes:
# - /tmp/lob-postgres-data:/var/lib/postgresql/data
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
Expand All @@ -19,7 +19,10 @@ services:
environment:
SPRING_CONFIG_LOCATIONS: classpath:/application.yml,classpath:/application-dev--yaci-dev-kit.yml
SPRING_PROFILES_ACTIVE: dev--yaci-dev-kit
entrypoint: ${ENTRYPOINT:-java -jar app.jar}
DB_URL: ${DB_USER:-jdbc:postgresql://postgres:5432/postgres}
lob_owner_account_mnemonic: ${LOB_OWNER_ACCOUNT_MNEMONIC:-ocean sad mixture disease faith once celery mind clay hidden brush brown you sponsor dawn good claim gloom market world online twist laptop thrive}
working_dir: /app
entrypoint: ${ENTRYPOINT:-java --enable-preview -jar /app.jar}
networks:
- lob
ports:
Expand All @@ -32,25 +35,11 @@ services:
- "traefik.http.routers.backend.entrypoints=websecure"
- "traefik.http.routers.backend.tls.certresolver=myresolver"
- "traefik.http.middlewares.https-redirect.headers.customrequestheaders.X-Forwarded-Proto=https"

volumes:
- ./:/app/
# rabbitmq:
# image: rabbitmq:3-management-alpine
# container_name: 'rabbitmq'
# ports:
# - "5672:5672"
# - "15672:15672"
# environment:
# RABBITMQ_DEFAULT_USER: 'guest'
# RABBITMQ_DEFAULT_PASS: 'guest'

# volumes:
# - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
# - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq

#volumes:
# postgres-data:
volumes:
postgres-data:

networks:
lob:
Expand Down

0 comments on commit 75b3f81

Please sign in to comment.