-
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 #11 from barclayd/deploy/working-gcp
- Loading branch information
Showing
18 changed files
with
193 additions
and
50 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,2 @@ | ||
# Default platform for all builds | ||
DOCKER_DEFAULT_PLATFORM=linux/amd64 |
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,2 @@ | ||
DEFAULT_INPUT_FILE_PATH=./test/data/input.txt | ||
OUTPUT_FILE_PATH=./test/data/output.txt | ||
DEFAULT_OUTPUT_FILE_PATH=./output.txt |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ RUN bun install | |
COPY . . | ||
|
||
EXPOSE 3000 | ||
CMD ["bun", "run", "start"] | ||
CMD ["bun", "start"] |
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 |
---|---|---|
@@ -1,24 +1,32 @@ | ||
steps: | ||
# Build the container image | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['build', '-t', 'gcr.io/mars-rover-439913/mars-rover:$COMMIT_SHA', '.'] | ||
|
||
args: [ | ||
'build', | ||
'-t', 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:$COMMIT_SHA', | ||
'-t', 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:latest', | ||
'.' | ||
] | ||
|
||
# Push the container image | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['push', 'gcr.io/mars-rover-439913/mars-rover:$COMMIT_SHA'] | ||
|
||
args: ['push', 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:$COMMIT_SHA'] | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['push', 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:latest'] | ||
|
||
# Deploy to Cloud Run | ||
- name: 'gcr.io/cloud-builders/gcloud' | ||
args: | ||
- 'run' | ||
- 'deploy' | ||
- 'mars-rover' | ||
- '--image' | ||
- 'gcr.io/mars-rover-439913/mars-rover:$COMMIT_SHA' | ||
- 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:$COMMIT_SHA' | ||
- '--region' | ||
- 'europe-west2' | ||
- '--platform' | ||
- 'managed' | ||
|
||
images: | ||
- 'gcr.io/mars-rover-439913/mars-rover:$COMMIT_SHA' | ||
- 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:$COMMIT_SHA' | ||
- 'europe-west2-docker.pkg.dev/$PROJECT_ID/mars-rover/mars-rover:latest' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
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,81 @@ | ||
provider "google" { | ||
project = var.project_id | ||
region = var.region | ||
} | ||
|
||
# Enable required APIs | ||
resource "google_project_service" "cloud_build_api" { | ||
service = "cloudbuild.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
resource "google_project_service" "cloud_run_api" { | ||
service = "run.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
resource "google_project_service" "artifact_registry_api" { | ||
service = "artifactregistry.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
# Artifact Registry | ||
resource "google_artifact_registry_repository" "docker_repo" { | ||
provider = google | ||
location = var.region | ||
repository_id = var.docker_repository_id | ||
format = "DOCKER" | ||
description = "Docker repository for Mars Rover" | ||
depends_on = [google_project_service.artifact_registry_api] | ||
} | ||
|
||
# Cloud Build Trigger | ||
resource "google_cloudbuild_trigger" "filename-trigger" { | ||
name = "Github" | ||
location = var.region | ||
|
||
github { | ||
owner = var.github_owner | ||
name = var.github_repository | ||
push { | ||
branch = "^main$" | ||
} | ||
} | ||
|
||
filename = "cloudbuild.yaml" | ||
|
||
service_account = "projects/${var.project_id}/serviceAccounts/[email protected]" | ||
|
||
depends_on = [google_project_service.cloud_build_api] | ||
} | ||
|
||
# Cloud Run Service | ||
resource "google_cloud_run_service" "cloud_run_service" { | ||
name = var.github_repository | ||
location = var.region | ||
|
||
template { | ||
spec { | ||
containers { | ||
image = "${var.region}-docker.pkg.dev/${var.project_id}/${var.docker_repository_id}/${var.github_repository}:latest" | ||
ports { | ||
container_port = var.port | ||
} | ||
} | ||
} | ||
} | ||
|
||
depends_on = [ | ||
google_artifact_registry_repository.docker_repo, | ||
google_project_service.cloud_run_api | ||
] | ||
} | ||
|
||
# Allow unauthenticated access | ||
resource "google_cloud_run_service_iam_member" "noauth" { | ||
location = google_cloud_run_service.cloud_run_service.location | ||
project = var.project_id | ||
service = google_cloud_run_service.cloud_run_service.name | ||
role = "roles/run.invoker" | ||
member = "allUsers" | ||
} |
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,14 @@ | ||
output "cloud_build_url" { | ||
description = "URL to view Cloud Build history" | ||
value = "https://console.cloud.google.com/cloud-build/builds;region=global?project=${var.project_id}" | ||
} | ||
|
||
output "cloud_run_url" { | ||
description = "URL to view Cloud Run history" | ||
value = "https://console.cloud.google.com/run/detail/${var.project_id}/services/mars-rover?project=${var.project_id}" | ||
} | ||
|
||
output "cloud_run_service_url" { | ||
description = "URL to view Cloud Run service" | ||
value = "https://mars-rover.${var.region}.run.app" | ||
} |
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,31 @@ | ||
variable "project_id" { | ||
description = "GCP Project ID" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "GCP Region" | ||
type = string | ||
default = "europe-west1" | ||
} | ||
|
||
variable "docker_repository_id" { | ||
description = "Docker Repository ID" | ||
type = string | ||
} | ||
|
||
variable "github_owner" { | ||
description = "GitHub Owner" | ||
type = string | ||
} | ||
|
||
variable "github_repository" { | ||
description = "GitHub Repository" | ||
type = string | ||
} | ||
|
||
variable "port" { | ||
description = "Port" | ||
type = number | ||
default = 3000 | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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 |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import { simulateMission } from './mars'; | ||
import { measurePerformance } from './utils'; | ||
import { getCommandLineArgs } from './utils/bun'; | ||
import { getCommandLineArgs, readFile } from './utils/bun'; | ||
|
||
const { filePath, isDev } = getCommandLineArgs(); | ||
|
||
measurePerformance( | ||
() => simulateMission(filePath ?? Bun.env.DEFAULT_INPUT_FILE_PATH, isDev), | ||
'Mission Simulation Complete 🚀', | ||
); | ||
Bun.serve({ | ||
async fetch() { | ||
await measurePerformance( | ||
async () => await simulateMission(filePath ?? Bun.env.DEFAULT_INPUT_FILE_PATH, isDev), | ||
'Mission Simulation Complete 🚀', | ||
); | ||
return new Response(await readFile(Bun.env.DEFAULT_OUTPUT_FILE_PATH ?? './output.txt'), { | ||
headers: { | ||
'Content-Type': 'text/plain', | ||
}, | ||
}); | ||
}, | ||
}); | ||
|
||
|
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