-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AwalaNetwork/internet-endpoint-codelab
Write Awala Internet Codelab
- Loading branch information
Showing
28 changed files
with
2,717 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
app-js/node_modules | ||
|
||
infrastructure/terraform.tfvars | ||
infrastructure/terraform.tfstate* | ||
infrastructure/.terraform/ |
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 @@ | ||
# Codelab example for the Awala Internet Endpoint on GCP |
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,7 @@ | ||
FROM node:20.3.1 | ||
WORKDIR /tmp/app | ||
COPY . ./ | ||
RUN npm install | ||
USER node | ||
CMD ["node", "--unhandled-rejections=strict", "./server.js"] | ||
EXPOSE 8080 |
Large diffs are not rendered by default.
Oops, something went wrong.
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,7 @@ | ||
{ | ||
"dependencies": { | ||
"@google-cloud/pubsub": "^4.0.6", | ||
"env-var": "^7.4.1", | ||
"fastify": "^4.24.3" | ||
} | ||
} |
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,47 @@ | ||
import { PubSub } from '@google-cloud/pubsub'; | ||
import envVar from 'env-var'; | ||
import Fastify from 'fastify'; | ||
|
||
const OUTGOING_MESSAGES_TOPIC = envVar.get('OUTGOING_MESSAGES_TOPIC') | ||
.required().asString(); | ||
|
||
const pubSubClient = new PubSub(); | ||
|
||
const fastify = Fastify({ logger: true }); | ||
|
||
fastify.get('/', async (_request, reply) => { | ||
// Used by the health check | ||
return reply.send('All good!'); | ||
}); | ||
|
||
fastify.post('/', async (request, reply) => { | ||
// Extract the message and its metadata | ||
const pingData = request.body.message.data; | ||
const pingMessageAttributes = request.body.message.attributes; | ||
const pingSenderId = pingMessageAttributes.source; | ||
const pingRecipientId = pingMessageAttributes.subject; | ||
|
||
// Send the pong message | ||
const pongEvent = { | ||
data: pingData, | ||
attributes: { | ||
source: pingRecipientId, | ||
subject: pingSenderId, | ||
}, | ||
}; | ||
const topic = pubSubClient.topic(OUTGOING_MESSAGES_TOPIC); | ||
await topic.publishMessage(pongEvent); | ||
|
||
return reply.send('Message processed'); | ||
}); | ||
|
||
const start = async () => { | ||
try { | ||
await fastify.listen({ port: 8080, host: '0.0.0.0' }); | ||
} catch (err) { | ||
fastify.log.error(err); | ||
process.exit(1); | ||
} | ||
} | ||
start(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,27 @@ | ||
variable "internet_address" {} | ||
variable "pohttp_server_domain" {} | ||
|
||
module "awala-endpoint" { | ||
source = "relaycorp/awala-endpoint/google" | ||
version = "1.8.20" | ||
|
||
backend_name = "pong" | ||
internet_address = var.internet_address | ||
|
||
project_id = var.google_project_id | ||
region = var.google_region | ||
|
||
pohttp_server_domain = var.pohttp_server_domain | ||
|
||
mongodb_uri = local.mongodb_uri | ||
mongodb_db = local.mongodb_db_name | ||
mongodb_user = mongodbatlas_database_user.main.username | ||
mongodb_password = random_password.mongodb_user_password.result | ||
} | ||
|
||
output "pohttp_server_ip_address" { | ||
value = module.awala-endpoint.pohttp_server_ip_address | ||
} | ||
output "bootstrap_job_name" { | ||
value = module.awala-endpoint.bootstrap_job_name | ||
} |
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,33 @@ | ||
variable "google_project_id" {} | ||
variable "google_credentials_path" {} | ||
variable "google_region" { | ||
default = "europe-west1" | ||
} | ||
|
||
locals { | ||
gcp_services = [ | ||
"run.googleapis.com", | ||
"compute.googleapis.com", | ||
"cloudkms.googleapis.com", | ||
"pubsub.googleapis.com", | ||
"secretmanager.googleapis.com", | ||
"iam.googleapis.com", | ||
] | ||
} | ||
|
||
provider "google" { | ||
project = var.google_project_id | ||
credentials = file(var.google_credentials_path) | ||
} | ||
|
||
provider "google-beta" { | ||
project = var.google_project_id | ||
credentials = file(var.google_credentials_path) | ||
} | ||
|
||
resource "google_project_service" "services" { | ||
for_each = toset(local.gcp_services) | ||
|
||
service = each.value | ||
disable_dependent_services = true | ||
} |
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,54 @@ | ||
variable "mongodbatlas_public_key" {} | ||
variable "mongodbatlas_private_key" {} | ||
variable "mongodbatlas_project_id" {} | ||
|
||
terraform { | ||
required_providers { | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
version = "~> 1.10.2" | ||
} | ||
} | ||
} | ||
|
||
provider "mongodbatlas" { | ||
public_key = var.mongodbatlas_public_key | ||
private_key = var.mongodbatlas_private_key | ||
} | ||
|
||
locals { | ||
mongodb_db_name = "main" | ||
mongodb_uri = "${mongodbatlas_serverless_instance.main.connection_strings_standard_srv}/?retryWrites=true&w=majority" | ||
} | ||
|
||
resource "mongodbatlas_serverless_instance" "main" { | ||
project_id = var.mongodbatlas_project_id | ||
name = "awala-endpoint" | ||
|
||
provider_settings_backing_provider_name = "GCP" | ||
provider_settings_provider_name = "SERVERLESS" | ||
provider_settings_region_name = "WESTERN_EUROPE" | ||
} | ||
|
||
resource "mongodbatlas_project_ip_access_list" "main" { | ||
project_id = var.mongodbatlas_project_id | ||
comment = "See https://github.com/relaycorp/terraform-google-awala-endpoint/issues/2" | ||
cidr_block = "0.0.0.0/0" | ||
} | ||
|
||
resource "mongodbatlas_database_user" "main" { | ||
project_id = var.mongodbatlas_project_id | ||
|
||
username = "awala-endpoint" | ||
password = random_password.mongodb_user_password.result | ||
auth_database_name = "admin" | ||
|
||
roles { | ||
role_name = "readWrite" | ||
database_name = local.mongodb_db_name | ||
} | ||
} | ||
|
||
resource "random_password" "mongodb_user_password" { | ||
length = 32 | ||
} |
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,6 +1,9 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "github-pages", "= 228", :group => :jekyll_plugins | ||
group :jekyll_plugins do | ||
gem "github-pages", "= 228" | ||
gem "jekyll-tabs", '~> 1.1' | ||
end | ||
|
||
# Work around https://github.com/jekyll/jekyll/issues/8523 | ||
gem "webrick", "~> 1.7" |
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,3 @@ | ||
<p class="fs-3"> | ||
Copyright 2023 by <a href="https://relaycorp.tech">Relaycorp</a>. | ||
</p> |
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,2 @@ | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/jekyll-tabs.css"/> | ||
<script src="{{ site.baseurl }}/assets/js/jekyll-tabs.js"></script> |
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,3 @@ | ||
<p class="fs-3 text-center mx-5"> | ||
<a href="https://awala.network">Go to awala.network.</a> | ||
</p> |
Oops, something went wrong.