Skip to content

Commit

Permalink
Merge pull request #10 from NTF-marketplace/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
min-96 authored Aug 6, 2024
2 parents 92648b9 + bed431a commit 29bf351
Show file tree
Hide file tree
Showing 54 changed files with 2,861 additions and 143 deletions.
199 changes: 199 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
name: Create and publish a container image, update helm chart 'appVersion'

on:
push:
branches: ["main", "develop"]

#############################################
#
# Branch
# - develop > GitHub packages
# - main > Amazon ECR
#
#############################################

jobs:
develop:
### Reference
# https://docs.github.com/ko/actions/publishing-packages/publishing-docker-images#github-packages%EC%97%90-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EA%B2%8C%EC%8B%9C
###

if: github.ref == 'refs/heads/develop'
name: Build and Push Container Image to GitHub Container Registry
runs-on: ubuntu-latest
env:
REPOSITORY: admin
ENVIRONMENT: dev
permissions:
contents: read
packages: write
attestations: write
id-token: write

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

- name: Log in to the GitHub container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Container image
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ghcr.io/${{ github.repository }}
tags: type=sha

- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '21'

- name: Build JAR
run: ./gradlew clean build -x test

- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# ### Error
# # [message] Failed to persist attestation
# # Feature not available for the NTF-marketplace organization.
# # To enable this feature, please upgrade the billing plan, or make this repository public.
# # https://docs.github.com/rest/repos/repos#create-an-attestation
# ###
# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# with:
# subject-name: ${{ env.REGISTRY }}/${{ github.repository }}
# subject-digest: ${{ steps.push.outputs.digest }}
# push-to-registry: true

- name: Checkout Private Repository
uses: actions/checkout@v4
with:
repository: NTF-marketplace/devops
fetch-depth: 0
ref: develop
token: ${{ secrets.PAT }}

- name: Replace image tag in helm values.yaml
uses: mikefarah/yq@master
env:
IMAGE_VERSION: ${{ steps.meta.outputs.version }}
with:
cmd: yq eval -i '.image.tag = env(IMAGE_VERSION)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml'

- name: Commit helm chart changes
env:
IMAGE_VERSION: ${{ steps.meta.outputs.version }}
run: |
cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}
git config --global user.email "[email protected]"
git config --global user.name "dongdorrong"
git add values.yaml
git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_VERSION"
- name: Push commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
repository: NTF-marketplace/devops
branch: develop

main:
if: github.ref == 'refs/heads/main'
name: Build and Push Container Image to Amazon ECR
runs-on: ubuntu-latest
env:
REPOSITORY: admin
ENVIRONMENT: prod
permissions:
contents: read
packages: write
attestations: write
id-token: write

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Extract metadata (tags, labels) for Container image
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}
tags: type=sha

- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '21'

- name: Build JAR
run: ./gradlew clean build -x test

- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Checkout Private Repository
uses: actions/checkout@v4
with:
repository: NTF-marketplace/devops
fetch-depth: 0
ref: develop
token: ${{ secrets.PAT }}

- name: Replace image tag in helm values.yaml
uses: mikefarah/yq@master
env:
IMAGE_VERSION: ${{ steps.meta.outputs.version }}
with:
cmd: yq eval -i '.image.tag = env(IMAGE_VERSION)' 'chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}/values.yaml'

- name: Commit helm chart changes
env:
IMAGE_VERSION: ${{ steps.meta.outputs.version }}
run: |
cd chart/${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }}
git config --global user.email "[email protected]"
git config --global user.name "dongdorrong"
git add values.yaml
git commit --message "ci: update ${{ env.REPOSITORY }}_${{ env.ENVIRONMENT }} image tag to $IMAGE_VERSION"
- name: Push commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT }}
repository: NTF-marketplace/devops
branch: develop
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM amazoncorretto:21-alpine

COPY build/libs/*.jar /app.jar

RUN apk update && apk upgrade && \
# apk add --no-cache <necessary-packages> && \
rm -rf /var/cache/apk/*

ENTRYPOINT ["java", "-jar", "app.jar"]
96 changes: 96 additions & 0 deletions Web3App/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.8.10'
id 'application'
id "com.github.johnrengelman.shadow" version "5.2.0"
id 'org.web3j' version '4.11.2'
}


group 'org.web3j'
version '0.1.0'

sourceCompatibility = 17

repositories {
mavenLocal()
mavenCentral()
maven { url "https://hyperledger.jfrog.io/hyperledger/besu-maven" }
maven { url "https://artifacts.consensys.net/public/maven/maven/" }
maven { url "https://splunk.jfrog.io/splunk/ext-releases-local" }
}

web3j {
generatedPackageName = 'org.web3j.generated.contracts'
excludedContracts = ['Mortal']
}

node {
nodeProjectDir.set(file("$projectDir"))
}

ext {
web3jVersion = '4.11.2'
logbackVersion = '1.4.14'
klaxonVersion = '5.5'
besuPluginVersion = '24.1.1'
besuInternalVersion = '24.1.1'
besuInternalCryptoVersion = '23.1.3'
besuCryptoDepVersion = '0.8.3'
}

dependencies {
implementation "org.web3j:core:$web3jVersion",
"ch.qos.logback:logback-core:$logbackVersion",
"ch.qos.logback:logback-classic:$logbackVersion",
"com.beust:klaxon:$klaxonVersion"
implementation "org.web3j:web3j-unit:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'

implementation "org.hyperledger.besu:plugin-api:$besuPluginVersion"
implementation "org.hyperledger.besu.internal:besu:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:api:$besuInternalVersion"
implementation "org.hyperledger.besu:evm:$besuPluginVersion"
implementation "org.hyperledger.besu.internal:config:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:core:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:crypto:$besuInternalCryptoVersion"
implementation "org.hyperledger.besu.internal:rlp:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:kvstore:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:metrics-core:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:trie:$besuInternalVersion"
implementation "org.hyperledger.besu.internal:util:$besuInternalVersion"
implementation "org.hyperledger.besu:bls12-381:$besuCryptoDepVersion"
implementation "org.hyperledger.besu:secp256k1:$besuCryptoDepVersion"
}

jar {
manifest {
attributes(
'Main-Class': 'org.web3j.Web3App',
'Multi-Release':'true'
)
}
}

application {
mainClassName = 'org.web3j.Web3App'
}

test {
useJUnitPlatform()
}

compileKotlin {
kotlinOptions.jvmTarget = "17"
}

compileTestKotlin {
kotlinOptions.jvmTarget = "17"
}

shadowJar {
zip64 = true
}
Binary file added Web3App/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions Web3App/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 29bf351

Please sign in to comment.