Skip to content

Commit

Permalink
APT-1507: z integration #10
Browse files Browse the repository at this point in the history
Co-authored-by: Łukasz Kosiak <[email protected]>
  • Loading branch information
lukozill and uHappyLogic authored Dec 10, 2024
1 parent 487523b commit 4069e1d
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 4 deletions.
46 changes: 46 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Emacs backup files.
*~
.\#*
\#*

# Secrets files.
**/config/**/*.secret.yaml
**/target

**/secrets.cache.yaml

# NextJS ignores

## dependencies
**/node_modules
**/.pnp
**/.pnp.js

## testing
**/coverage

## next.js
**/.next/
**/.env*.local

## production
**/build

## misc
**/.DS_Store
**/*.pem

## debug
**/npm-debug.log*
**/yarn-debug.log*
**/yarn-error.log*
**/.pnpm-debug.log*

## Github

.github

## z

renders
zenv
102 changes: 102 additions & 0 deletions .github/workflows/gha_app_zq2-staking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: "CICD zq2-staking"

on:
# Test run before merging
pull_request:
branches:
- main
# On merged
push:
branches:
- main
# On released
release:
types: [published]

jobs:
build-docker-buildx-stg:
permissions:
id-token: write
contents: write
runs-on: ubuntu-22.04
if: github.actor != 'dependabot[bot]' && (github.event_name == 'pull_request' || github.event_name == 'push') && github.ref_name == 'main'
name: "Deploy image STG"
strategy:
fail-fast: false
matrix:
application:
[
zq2-staking/zq2-staking-frontend,
]
include:
- application: zq2-staking/zq2-staking-frontend
image_name: zq2-staking-frontend
file: images/frontend/Dockerfile
context: .
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: "true"
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0

- name: Docker build and push
uses: Zilliqa/gh-actions-workflows/actions/ci-dockerized-app-build-push@v2
with:
file: ${{ matrix.file }}
context: ${{ matrix.context }}
push: ${{ github.ref_name == github.event.repository.default_branch }}
tag: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private/${{ matrix.image_name }}
tag-length: 8
tag-latest: false
registry: asia-docker.pkg.dev
workload-identity-provider: "${{ secrets.GCP_PRD_GITHUB_WIF }}"
service-account: "${{ secrets.GCP_STG_GITHUB_SA_DOCKER_REGISTRY }}"
cache-key: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private/${{ matrix.image_name }}-cache
build-args: |
DEPLOY_ENV=stg
build-docker-buildx-prd:
permissions:
id-token: write
contents: write
runs-on: ubuntu-22.04
if: github.event_name == 'release'
name: "Deploy image PRD"
strategy:
fail-fast: false
matrix:
application:
[
zq2-staking/zq2-staking-frontend,
]
include:
- application: zq2-staking/zq2-staking-frontend
image_name: zq2-staking-frontend
file: images/frontend/Dockerfile
context: .
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: "true"
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0

- name: Docker build and push
uses: Zilliqa/gh-actions-workflows/actions/ci-dockerized-app-build-push@v2
with:
file: ${{ matrix.file }}
context: ${{ matrix.context }}
push: true
tag: asia-docker.pkg.dev/prj-p-devops-services-tvwmrf63/zilliqa-private/${{ matrix.image_name }}:${{ github.ref_name }}
tag-latest: true
registry: asia-docker.pkg.dev
workload-identity-provider: "${{ secrets.GCP_PRD_GITHUB_WIF }}"
service-account: "${{ secrets.GCP_PRD_GITHUB_SA_DOCKER_REGISTRY }}"
cache-key: asia-docker.pkg.dev/prj-p-devops-services-tvwmrf63/zilliqa-private/${{ matrix.image_name }}-cache
build-args: |
DEPLOY_ENV=prd
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ yarn-error.log*

# local env files
.env*.local

# vercel
.vercel
.env

# typescript
*.tsbuildinfo
next-env.d.ts

.env

## z
zenv/dev-data
renders/
secrets.cache.yaml
3 changes: 3 additions & 0 deletions etc/testnet/secret_spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zq2_staking:
wallet_connect_api_key:
_op: "op://prj-d-staging/zq2-staking/WALLET_CONNECT_API_KEY"
40 changes: 40 additions & 0 deletions images/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM node:20 AS builder

WORKDIR /build
COPY . .

RUN npm install
RUN npm run build

FROM node:20-alpine AS runner

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app

ENV NODE_ENV production
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder --chown=nextjs:nodejs /build/.next/standalone .
COPY --from=builder --chown=nextjs:nodejs /build/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /build/.next/server ./.next/server
COPY --from=builder /build/public ./public

COPY --from=builder --chown=nextjs:nodejs /build/etc ./etc

RUN chown nextjs:nodejs ./.next

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD ["node", "./server.js"]
20 changes: 20 additions & 0 deletions images/frontend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: all
all: image/build-and-push

.ONESHELL:
SHELL := /bin/bash
.SHELLFLAGS = -ec

ENVIRONMENT ?= dev
VALID_ENVIRONMENTS := dev stg prd
IMAGE_TAG ?= localhost:5001/zq2-staking-frontend:latest

# Check if the ENVIRONMENT variable is in the list of valid environments
ifeq ($(filter $(ENVIRONMENT),$(VALID_ENVIRONMENTS)),)
$(error Invalid value for ENVIRONMENT. Valid values are dev, stg, or prd.)
endif

## Build and push the Docker image
image/build-and-push:
cd ../../ && docker build -f images/frontend/Dockerfile -t "${IMAGE_TAG}" .
docker push "${IMAGE_TAG}"
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
reactStrictMode: true,
i18n: {
locales: ["en"],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"local_z": "npx tsx scripts/run-dev.ts",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
40 changes: 40 additions & 0 deletions render_config_staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
project_id: prj-d-staging-6zj2hygf
bastion_instance_name: vm-d-staging-bastion-ase1
bastion_instance_zone: asia-southeast1-a
region: asia-southeast1

k8s_clusters:
staging:
project_id: "prj-d-staging-6zj2hygf"
name: gke-d-staging-01-ase1

registry: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-private

dbs_to_instances: []

apps_to_clusters:
- name_re: main/zq2-staking/zq2-staking-frontend
cluster: staging
dns_name: zq2-staking.zilstg.dev
healthcheck:
request_path: /health
image_name: zq2-staking-frontend
namespace: zq2-staking-stg
pipeline:
dockerfile_path: images/frontend/Dockerfile
context: .
replicas: 1
env_vars:
- name: ZQ2_STAKING_CHAIN_ID
value: 33469
pod_limits:
cpu: 200m
memory: 200Mi
pod_requests:
cpu: 100m
memory: 100Mi

secrets:
zq2_staking:
wallet_connect_api_key:
_op: "op://prj-d-staging/zq2-staking/WALLET_CONNECT_API_KEY"
20 changes: 20 additions & 0 deletions scripts/run-dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const cli = require("next/dist/cli/next-dev");

const overridePort = process.env.Z_LISTEN_PORT;

if (process.argv.length > 2 && process.argv[2] === "set_env") {
process.env.Z_CONFIG = "../etc/testnet";
}

if (overridePort === undefined) {
console.log("running on default nextjs port");
cli.nextDev({
_: [null],
});
} else {
console.log("overridePort", overridePort);
cli.nextDev({
_: [null],
"port": Number.parseInt(overridePort),
});
}
11 changes: 11 additions & 0 deletions setenv/testnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if [[ "$SHELL" == *"zsh"* ]] ; then
echo "Running on $SHELL ..."
BASEDIR=`realpath $(dirname "$0")`/..
else
BASEDIR=`realpath $(dirname "$BASH_SOURCE")`/..
fi

export Z_ENV=${BASEDIR}/zenv
export Z_CONFIG=${BASEDIR}/etc/testnet

source ${BASEDIR}/../devops/setenv
26 changes: 26 additions & 0 deletions zenv/z.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
backend: kind
kind: zq2staking
clusters:
main:
aws_name: dev
aws_region: eu-west-2
container_registry: foo
# Manifests are add-ons, deployed to your cluster to add functionality.
manifests: {}
# applications: these will be pulled from your git repository.
apps:
zq2-staking:
path: z/zq2-staking
track: development
type: kustomize
dev:
- path: .
name: zq2-staking-frontend
command: npm run local_z
is_entrypoint: true
env_vars:
- name: ZQ2_STAKING_CHAIN_ID
value: 33469
secrets:
- name: ZQ2_STAKING_WALLET_CONNECT_API_KEY
from: zq2_staking.wallet_connect_api_key

0 comments on commit 4069e1d

Please sign in to comment.