-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db9f805
commit 8db8267
Showing
12 changed files
with
335 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
MAKEFILE_OVERWRITE_DOCKERNAME= | ||
INITIAL_BEARER_TOKEN= | ||
MONGO_URI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
name: Testnet | ||
|
||
on: | ||
push: | ||
branches: | ||
- testnet | ||
|
||
workflow_dispatch: | ||
inputs: | ||
reason: | ||
description: 'Reason for manual trigger' | ||
required: false | ||
default: 'Manual build and deploy' | ||
|
||
jobs: | ||
cloud_build-local_docker: | ||
runs-on: ubuntu-latest | ||
if: github.ref != 'refs/heads/dev' | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Make production envfile | ||
uses: SpicyPizza/create-envfile@v2.0 | ||
with: | ||
envkey_PORT: ${{ vars.ENVKEY_PORT }} | ||
envkey_INITIAL_BEARER_TOKEN: ${{ vars.INITIAL_BEARER_TOKEN }} | ||
envkey_MAKEFILE_OVERWRITE_DOCKERNAME: ${{ vars.MAKEFILE_OVERWRITE_DOCKERNAME }} | ||
sort_keys: false | ||
file_name: .env.local | ||
|
||
- name: Set environment variable | ||
run: echo "CI=false" >> $GITHUB_ENV | ||
|
||
- name: Check version | ||
run: make version | ||
|
||
- name: Build the docker image | ||
run: make composebuild-prod | ||
|
||
- name: Display image_id variable | ||
run: make print_image_id | ||
|
||
- name: Compress the image.tar | ||
run: make save_image_as_tar | ||
|
||
- name: Set Docker image name & PORT number | ||
run: | | ||
export FOLDER_NAME=$(make echo_foldername) | ||
echo "FOLDER_NAME=$FOLDER_NAME" >> $GITHUB_ENV | ||
export DOCKER_IMAGE_NAME=$(make echo_docker_image_name) | ||
echo "DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME" >> $GITHUB_ENV | ||
export APPLICATION_PORT=$(grep '^PORT=' .env.local | cut -d= -f2 | tr -d '\n') | ||
echo "APPLICATION_PORT=$APPLICATION_PORT" >> $GITHUB_ENV | ||
- name: Check files | ||
run: ls -a | ||
|
||
- name: SCP file to server | ||
uses: appleboy/scp-action@v0.1.4 | ||
with: | ||
host: ${{ secrets.REMOTE_HOST_TESTNET }} | ||
username: ${{ secrets.REMOTE_USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
port: ${{ secrets.REMOTE_PORT }} | ||
source: "${{ env.DOCKER_IMAGE_NAME }}.tar.gz,Makefile" | ||
target: ./${{ env.FOLDER_NAME }}/ # Target is based on the host:username login path. Will create non-existant folders. | ||
|
||
- name: Setup SSH and deploy | ||
uses: appleboy/ssh-action@v1.0.0 | ||
with: | ||
host: ${{secrets.REMOTE_HOST_TESTNET}} | ||
username: ${{secrets.REMOTE_USERNAME}} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
port: ${{ secrets.REMOTE_PORT }} | ||
script: | | ||
cd ${{ env.FOLDER_NAME }} | ||
ls | ||
# | ||
# Prepare stop & delete | ||
# Docker | ||
make stop_matching_containers | ||
make delete_matching_images | ||
# | ||
# Dockerfile | ||
if command -v pigz &> /dev/null | ||
then | ||
unpigz -f "${{ env.DOCKER_IMAGE_NAME }}.tar.gz" | ||
else | ||
gunzip -f "${{ env.DOCKER_IMAGE_NAME }}.tar.gz" | ||
fi | ||
# | ||
# Load Docker | ||
# | ||
docker load -i ${{env.DOCKER_IMAGE_NAME}}.tar | ||
make print_image_id | ||
make run_container PORT=${{ env.APPLICATION_PORT }} | ||
# | ||
# Cleanup | ||
# | ||
#ls | ||
rm ${{env.DOCKER_IMAGE_NAME}}.tar | ||
rm Makefile | ||
cd .. | ||
rmdir ${{env.FOLDER_NAME}} | ||
- name: Print end of script message | ||
run: echo "Good Morning... You have arrived at the end of the script 0.0/" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// src/dbcode/mongoDbClient.ts | ||
|
||
import { MongoClient, Db } from 'mongodb'; | ||
import { IDbClient } from '../types/dbInterfaces'; | ||
|
||
class MongoDbClient implements IDbClient { | ||
private client: MongoClient; | ||
private db: Db | null = null; | ||
|
||
constructor(uri: string) { | ||
this.client = new MongoClient(uri); | ||
} | ||
|
||
async connect() { | ||
await this.client.connect(); | ||
this.db = this.client.db('yourDatabaseName'); | ||
console.log('Connected to MongoDB'); | ||
} | ||
|
||
async setBearerTokenDB(token: string): Promise<boolean> { | ||
if (!this.db) throw new Error('Database not connected'); | ||
const collection = this.db.collection('bearer_tokens'); | ||
const existingToken = await collection.findOne({}); | ||
if (existingToken) return false; | ||
await collection.insertOne({ token }); | ||
return true; | ||
} | ||
|
||
async isValidBearerTokenDB(token: string): Promise<boolean> { | ||
if (!this.db) throw new Error('Database not connected'); | ||
const collection = this.db.collection('bearer_tokens'); | ||
const result = await collection.findOne({ token }); | ||
return !!result; | ||
} | ||
|
||
async getCurrentBearerTokenDB(): Promise<string | null> { | ||
if (!this.db) throw new Error('Database not connected'); | ||
const collection = this.db.collection('bearer_tokens'); | ||
const result = await collection.findOne({}); | ||
return result ? result.token : null; | ||
} | ||
|
||
async changeBearerTokenDB(currentToken: string, newToken: string): Promise<boolean> { | ||
if (!this.db) throw new Error('Database not connected'); | ||
const collection = this.db.collection('bearer_tokens'); | ||
const result = await collection.updateOne({ token: currentToken }, { $set: { token: newToken } }); | ||
return result.modifiedCount > 0; | ||
} | ||
} | ||
|
||
export default MongoDbClient; |
Oops, something went wrong.