Skip to content

Commit

Permalink
feat: atlasnet
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Sep 3, 2024
1 parent 8991bc7 commit c0ff0ca
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 205 deletions.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: '[Bug]'
labels: bug
assignees: ngundotra
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Example Links**

- [Please provide at least 1 link here](https://explorer.solana.com)

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
61 changes: 61 additions & 0 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 'Deploy to Cloud Run'
description: 'Deploys a service or job to Cloud Run with optional immediate execution for jobs'

inputs:
environment:
required: true
description: 'Deployment environment'
default: 'dev'
repository:
required: true
description: 'Artifact repository'
default: 'artifacts-0'
project-name:
required: true
description: 'Name of the project'
gcp-project-id:
required: true
description: 'Google Cloud Project ID'
app-name:
required: true
description: 'Name of the application'
gcp-auth-key:
required: true
description: 'GCP authentication key'
image-name:
required: true
description: 'Name of the Docker image'
deploy-type:
required: true
default: service
description: 'Type of deployment: "service" or "job"'
execute-immediately:
required: false
default: "false"
description: 'Whether to execute the job immediately after deployment (only for jobs)'

runs:
using: 'composite'
steps:
- shell: bash
run: echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"

- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ inputs.gcp-auth-key }}

- uses: google-github-actions/setup-gcloud@v2

- uses: google-github-actions/deploy-cloudrun@v2
with:
project_id: ${{ inputs.gcp-project-id }}
${{ inputs.deploy-type == 'job' && 'job' || 'service' }}: ${{ inputs.app-name }}
image: us-central1-docker.pkg.dev/${{ inputs.repository }}/${{ inputs.project-name }}/${{ inputs.image-name }}:sha-${{ env.sha_short }}

- name: Execute Job Immediately
if: inputs.deploy-type == 'job' && inputs.execute-immediately == 'true'
shell: bash
run: |
gcloud run jobs execute ${{ inputs.app-name }} \
--project ${{ inputs.gcp-project-id }} \
--region us-central1
64 changes: 64 additions & 0 deletions .github/actions/release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Build and Release Docker image'
description: ''

inputs:
repository:
required: true
description: ''
default: 'artifacts-0'
project-name:
required: true
description: ''
app-name:
required: true
description: ''
default: ''
gcp-auth-key:
required: true
description: ''
default: ''

runs:
using: 'composite'
steps:
- uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.CONFIG_YAML }}
filename: "config.yaml"
is-executable: false
working-directory: "./"
- uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.CONFIG_ATLASNET_YAML }}
filename: "config-atlasnet.yaml"
is-executable: false
working-directory: "./"
- uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.ID_JSON }}
filename: "id.json"
is-executable: false
working-directory: "./"
- uses: docker/metadata-action@v5
id: metadata
with:
images: us-central1-docker.pkg.dev/${{ inputs.repository }}/${{ inputs.project-name }}/${{ inputs.app-name }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- uses: docker/login-action@v3
with:
username: _json_key
password: '${{ inputs.gcp-auth-key }}'
registry: 'us-central1-docker.pkg.dev'
- uses: int128/kaniko-action@v1
with:
push: true
file: Dockerfile
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache: true
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
registries:
npmjs:
type: npm-registry
url: https://registry.npmjs.org
token: ${{secrets.NPM_TOKEN}}
updates:
- package-ecosystem: "docker"
directory: "/docker"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "npm"
registries:
- npmjs
directory: "/"
schedule:
interval: "daily"
12 changes: 12 additions & 0 deletions .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Auto approve

on: pull_request_target

jobs:
auto-approve:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.actor == 'dependabot[bot]'
steps:
- uses: hmarr/auto-approve-action@v4
29 changes: 29 additions & 0 deletions .github/workflows/deploy-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: deploy

on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
GCP_AUTH_KEY:
required: true
jobs:


deploy-ping:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/deploy
with:
deploy-type: service
environment: ${{ inputs.environment }}
gcp-project-id: fuzzy-lemur-${{ inputs.environment }}
gcp-auth-key: ${{ secrets.GCP_AUTH_KEY }}
repository: "artifacts-0"
project-name: "atlasnet"
app-name: "ping-api"
image-name: "ping"
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: deploy

on:
push:
branches: [ 'main' ]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/release
with:
repository: "artifacts-0"
project-name: "atlasnet"
app-name: "ping"
gcp-auth-key: ${{ secrets.GCP_AUTH_KEY }}

deploy-test:
needs: [ release ]
uses: ./.github/workflows/deploy-app.yml
with:
environment: 'test'
secrets: inherit
20 changes: 20 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: build-lint-test

on:
merge_group:
pull_request:
branches: ['main']
types: [synchronize, opened, reopened]

jobs:

docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/release
with:
repository: 'artifacts-0'
project-name: 'atlasnet'
app-name: 'ping'
gcp-auth-key: ${{ secrets.GCP_AUTH_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ config-devnet.yaml
# Go workspace file
go.work.*

id.json
config-atlasnet.yaml
.idea/
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.22 AS builder
WORKDIR /workspace
COPY . .
RUN go build -o app .

FROM debian:latest
RUN \
apt-get update && \
apt-get install ca-certificates curl vim -y
WORKDIR /workspace
COPY --from=builder /workspace/app .
COPY --from=builder /workspace/config.yaml .
COPY --from=builder /workspace/config-atlasnet.yaml .
COPY --from=builder /workspace/id.json .

CMD ["./app"]
71 changes: 12 additions & 59 deletions apiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,59 +51,14 @@ func APIService(c ClustersToRun) {
}
// Single Cluster or all Cluster
switch c {
case RunMainnetBeta:
if config.Mainnet.APIServer.Enabled {
go runCluster(config.Mainnet.APIServer.Mode,
config.Mainnet.APIServer.IP,
config.Mainnet.APIServer.SSLIP,
config.Mainnet.APIServer.KeyPath,
config.Mainnet.APIServer.CrtPath)
log.Println("--- API Server Mainnet Start--- ")
}

case RunTestnet:
if config.Testnet.APIServer.Enabled {
go runCluster(config.Testnet.APIServer.Mode,
config.Testnet.APIServer.IP,
config.Testnet.APIServer.SSLIP,
config.Testnet.APIServer.KeyPath,
config.Testnet.APIServer.CrtPath)
log.Println("--- API Server Testnet Start--- ")
}

case RunDevnet:
if config.Devnet.APIServer.Enabled {
go runCluster(config.Devnet.APIServer.Mode,
config.Devnet.APIServer.IP,
config.Devnet.APIServer.SSLIP,
config.Devnet.APIServer.KeyPath,
config.Devnet.APIServer.CrtPath)
log.Println("--- API Server Devnet Start--- ")
}
case RunAllClusters:
if config.Mainnet.APIServer.Enabled {
go runCluster(config.Mainnet.APIServer.Mode,
config.Mainnet.APIServer.IP,
config.Mainnet.APIServer.SSLIP,
config.Mainnet.APIServer.KeyPath,
config.Mainnet.APIServer.CrtPath)
log.Println("--- API Server Mainnet Start--- ")
}
if config.Testnet.APIServer.Enabled {
go runCluster(config.Testnet.APIServer.Mode,
config.Testnet.APIServer.IP,
config.Testnet.APIServer.SSLIP,
config.Testnet.APIServer.KeyPath,
config.Testnet.APIServer.CrtPath)
log.Println("--- API Server Testnet Start--- ")
}
if config.Devnet.APIServer.Enabled {
go runCluster(config.Devnet.APIServer.Mode,
config.Devnet.APIServer.IP,
config.Devnet.APIServer.SSLIP,
config.Devnet.APIServer.KeyPath,
config.Devnet.APIServer.CrtPath)
log.Println("--- API Server Devnet Start--- ")
case RunAtlasnet:
if config.Atlasnet.APIServer.Enabled {
go runCluster(config.Atlasnet.APIServer.Mode,
config.Atlasnet.APIServer.IP,
config.Atlasnet.APIServer.SSLIP,
config.Atlasnet.APIServer.KeyPath,
config.Atlasnet.APIServer.CrtPath)
log.Println("--- API Server Atlasnet Start--- ")
}

default:
Expand All @@ -119,12 +74,8 @@ func getRPCEndpoint(c *gin.Context) {
cluster := c.Param("cluster")
var e *FailoverEndpoint
switch cluster {
case "mainnet-beta":
e = mainnetFailover.GetEndpoint()
case "testnet":
e = testnetFailover.GetEndpoint()
case "devnet":
e = devnetFailover.GetEndpoint()
case "atlasnet":
e = atlasnetFailover.GetEndpoint()
default:
c.AbortWithStatus(http.StatusNotFound)
log.Println("StatusNotFound Error:", cluster)
Expand Down Expand Up @@ -159,6 +110,8 @@ func last6hours(c *gin.Context) {
cluster := c.Param("cluster")
var ret []DataPoint1MinResultJSON
switch cluster {
case "atlasnet":
ret = GetLast6hours(Atlasnet, HasComputeUnitPrice, 0)
case "mainnet-beta":
ret = GetLast6hours(MainnetBeta, HasComputeUnitPrice, 0)
case "testnet":
Expand Down
Loading

0 comments on commit c0ff0ca

Please sign in to comment.