Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update CI to rebuild image #1550

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/gke-preview.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
name: Build and Deploy to GKE Preview

on:
workflow_dispatch:
release:
types: [prereleased]

# Environment variables available to all jobs and steps in this workflow
env:
GITHUB_SHA: ${{ github.sha }}
REGISTRY_HOSTNAME: gcr.io
GKE_PROJECT: console-labs-prod
IMAGE: consolelabs/mochi-discord
K8S_ENVIRONMENT: preview
SHA: ${{ github.sha }}

jobs:
setup-build-publish-deploy:
Expand All @@ -33,11 +34,16 @@ jobs:
run: |
gcloud auth configure-docker gcr.io

# Overwrite GITHUB_SHA
- name: Set SHA
if: github.event_name == 'workflow_dispatch'
run: |
echo "SHA=${GITHUB_SHA}-$(date +%Y%m%d%H%M%S)" >> "$GITHUB_ENV"
# Build & Push the Docker image
- name: Build & Push
run: |
docker build --build-arg NODE_ENV=$K8S_ENVIRONMENT --build-arg SWAGGER_URL=${{ secrets.SWAGGER_URL_DEV }} -t $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA} .
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA}
docker build --build-arg NODE_ENV=$K8S_ENVIRONMENT --build-arg SWAGGER_URL=${{ secrets.SWAGGER_URL_DEV }} -t $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA} .
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}

# Setup kustomize
- name: Setup kustomize
Expand All @@ -57,8 +63,8 @@ jobs:
cd ./infrastructure/mochi-discord/$K8S_ENVIRONMENT
git config user.name jphuc96
git config user.email [email protected]
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA}
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}
cd ../v2-preview
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_SHA}
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}
git commit -am "[skip ci] mochi-discord ${K8S_ENVIRONMENT} image update"
git push origin main
23 changes: 17 additions & 6 deletions .github/workflows/gke-prod.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name: Build and Deploy to GKE Prod

on:
workflow_dispatch:
release:
types: [released]

# Environment variables available to all jobs and steps in this workflow
env:
REGISTRY_HOSTNAME: gcr.io
GKE_PROJECT: console-labs-prod
IMAGE: consolelabs/mochi-discord
K8S_ENVIRONMENT: prod
SHA: ${{ github.sha }}

jobs:
setup-build-publish-deploy:
Expand All @@ -32,11 +34,19 @@ jobs:
run: |
gcloud auth configure-docker gcr.io

# Overwrite GITHUB_SHA
- name: Set SHA
if: github.event_name == 'workflow_dispatch'
run: |
echo "SHA=${GITHUB_SHA}-$(date +%Y%m%d%H%M%S)" >> "$GITHUB_ENV"
# Build & Push the Docker image
- name: Build & Push
run: |
docker build -t $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_REF_NAME} .
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_REF_NAME}
docker tag $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_REF_NAME} $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}
docker push $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}

# Setup kustomize
- name: Setup kustomize
run: |
Expand All @@ -55,9 +65,9 @@ jobs:
cd ./infrastructure/mochi-discord/$K8S_ENVIRONMENT
git config user.name jphuc96
git config user.email [email protected]
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_REF_NAME}
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}
cd ../v2
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${GITHUB_REF_NAME}
/tmp/kustomize edit set image $REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE=$REGISTRY_HOSTNAME/$GKE_PROJECT/$IMAGE:${SHA}
git commit -am "[skip ci] mochi-discord ${K8S_ENVIRONMENT} image update"
git push origin main

Expand All @@ -68,12 +78,13 @@ jobs:
steps:
- name: Notify changelog
uses: fjogeleit/http-request-action@v1
if: github.event_name == 'release'
with:
url: 'https://chglg.fly.dev/v1/changelog'
method: 'POST'
url: "https://chglg.fly.dev/v1/changelog"
method: "POST"
customHeaders: '{"Content-Type": "application/json"}'
timeout: 30000
escapeData: 'true'
escapeData: "true"
data: >-
{
"repo": "https://github.com/${{ github.repository }}",
Expand Down
33 changes: 32 additions & 1 deletion src/commands/v/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { SlashCommandBuilder } from "@discordjs/builders"
import { SlashCommand } from "types/common"
import fs from "fs/promises"
import path from "path"
import { version } from "../../../package.json"

const slashCmd: SlashCommand = {
Expand All @@ -11,9 +13,38 @@ const slashCmd: SlashCommand = {
.setDescription("Check bot's version and running environment")
},
run: async function () {
const uiVersion = await fs
.readFile(
path.resolve(
process.cwd(),
"node_modules",
"@consolelabs/mochi-ui",
"package.json",
),
{ encoding: "utf8" },
)
.then((pkg) => JSON.parse(pkg).version)
.catch(() => "")

const restVersion = await fs
.readFile(
path.resolve(
process.cwd(),
"node_modules",
"@consolelabs/mochi-rest",
"package.json",
),
{ encoding: "utf8" },
)
.then((pkg) => JSON.parse(pkg).version)
.catch(() => "")
return {
messageOptions: {
content: `v${version} ⎯ ${process.env.NODE_ENV}`,
content: [
`v${version} ⎯ ${process.env.NODE_ENV}`,
`\`mochi-ui@${uiVersion}\``,
`\`mochi-rest@${restVersion}\``,
].join("\n"),
},
}
},
Expand Down
53 changes: 30 additions & 23 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ModelChain {
id?: number
name?: string
short_name?: string
type?: string
}

export interface ModelCoingeckoSupportedTokens {
Expand All @@ -55,6 +56,16 @@ export interface ModelCoingeckoSupportedTokens {
symbol?: string
}

export interface ModelCommandPermission {
code?: string
created_at?: string
description?: string
discord_permission_flag?: string
id?: number
need_dm?: boolean
updated_at?: string
}

export interface ModelConfigXpLevel {
level?: number
min_xp?: number
Expand Down Expand Up @@ -338,14 +349,20 @@ export interface ModelNewListedNFTCollection {
}

export interface ModelOffchainTipBotToken {
address?: string
chain?: ModelChain
chain_id?: string
coin_gecko_id?: string
created_at?: string
decimal?: number
icon?: string
id?: string
is_native?: boolean
service_fee?: number
status?: number
token_id?: string
token_name?: string
token_price?: number
token_symbol?: string
updated_at?: string
}
Expand Down Expand Up @@ -465,16 +482,6 @@ export interface ModelToken {
symbol?: string
}

export interface ModelTonoCommandPermission {
code?: string
created_at?: string
description?: string
discord_permission_flag?: string
id?: number
need_dm?: boolean
updated_at?: string
}

export interface ModelUser {
discriminator?: string
guild_users?: ModelGuildUser[]
Expand Down Expand Up @@ -797,8 +804,6 @@ export interface RequestOffchainTransferRequest {
platform?: string
recipients?: string[]
sender?: string

/** AmountString string `json:"amount_string"` */
token?: string
transfer_type?: string
}
Expand Down Expand Up @@ -856,8 +861,9 @@ export interface RequestTrackWalletRequest {

export interface RequestTransferV2Request {
all?: boolean
amount?: number
chain_id?: string
amount: number
chain_id: string
channel_avatar?: string
channel_id?: string
channel_name?: string
channel_url?: string
Expand All @@ -868,11 +874,12 @@ export interface RequestTransferV2Request {
moniker?: string
original_amount?: number
original_tx_id?: string
platform?: string
recipients?: string[]
sender?: string
token?: string
transfer_type?: "transfer" | "airdrop"
platform: "discord" | "telegram" | "web"
recipients: string[]
sender: string
theme_id?: number
token: string
transfer_type: "transfer" | "airdrop"
}

export interface RequestUnlinkBinance {
Expand Down Expand Up @@ -1122,6 +1129,10 @@ export interface ResponseCollectionSuggestions {
symbol?: string
}

export interface ResponseCommandPermissions {
data?: ModelCommandPermission[]
}

export interface ResponseCompareTokenReponseData {
base_coin?: ResponseGetCoinResponse
base_coin_suggestions?: ModelCoingeckoSupportedTokens[]
Expand Down Expand Up @@ -2297,10 +2308,6 @@ export interface ResponseTokenPriceAlertResponseData {
value?: number
}

export interface ResponseTonoCommandPermissions {
data?: ModelTonoCommandPermission[]
}

export interface ResponseTopUser {
author?: ModelGuildUserXP
leaderboard?: ModelGuildUserXP[]
Expand Down
Loading