Skip to content

Commit

Permalink
Merge pull request #3 from tryolabs/feature/part3
Browse files Browse the repository at this point in the history
Feature/part3
  • Loading branch information
FlorenciaOjeda authored Jun 27, 2024
2 parents 1b5aada + 132939c commit 03a4881
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 5 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.env
25 changes: 23 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# syntax=docker/dockerfile:1.2
FROM python:latest
# put you docker configuration here
FROM python:3.9-slim

# Set the working directory
WORKDIR /app

# Install build dependencies
RUN apt-get update && \
apt-get install -y build-essential gcc libssl-dev

# Copy requirements files for the container
COPY requirements*.txt ./

# Install Python dependencies
RUN pip install -r requirements.txt -r requirements-dev.txt

# Copy the entire project into the container
COPY . .

# Expose port
EXPOSE 8000

# Run the application inside the container
CMD ["uvicorn", "challenge.api:app", "--host", "0.0.0.0", "--port", "8000"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install: ## Install dependencies
pip install -r requirements-test.txt
pip install -r requirements.txt

STRESS_URL = http://127.0.0.1:8000
STRESS_URL = https://latam-challenge-7eedzyco2q-uc.a.run.app
.PHONY: stress-test
stress-test:
# change stress url to your deployed app
Expand All @@ -42,4 +42,4 @@ api-test: ## Run tests and coverage

.PHONY: build
build: ## Build locally the python artifact
python setup.py bdist_wheel
python setup.py bdist_wheel
21 changes: 21 additions & 0 deletions challenge/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions challenge/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
provider "google" {
project = var.project_id
region = var.region
}

resource "google_cloud_run_service" "latam_challenge_service" {
name = "latam-challenge"
location = var.region

template {
spec {
containers {
image = var.image_url

ports {
container_port = 8000
}
}
}
}

traffic {
percent = 100
latest_revision = true
}
}

resource "google_cloud_run_service_iam_policy" "noauth" {
location = google_cloud_run_service.latam_challenge_service.location
project = google_cloud_run_service.latam_challenge_service.project
service = google_cloud_run_service.latam_challenge_service.name

policy_data = data.google_iam_policy.noauth.policy_data
}

data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"

members = [
"allUsers",
]
}
}
4 changes: 4 additions & 0 deletions challenge/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "service_url" {
description = "The URL of the deployed Cloud Run service"
value = google_cloud_run_service.latam_challenge_service.status[0].url
}
228 changes: 228 additions & 0 deletions challenge/terraform/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
{
"version": 4,
"terraform_version": "1.5.2",
"serial": 11,
"lineage": "41caa1a9-fd55-f2c3-6cf1-50daff5a262d",
"outputs": {
"service_url": {
"value": "https://latam-challenge-7eedzyco2q-uc.a.run.app",
"type": "string"
}
},
"resources": [
{
"mode": "data",
"type": "google_iam_policy",
"name": "noauth",
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"audit_config": null,
"binding": [
{
"condition": [],
"members": [
"allUsers"
],
"role": "roles/run.invoker"
}
],
"id": "3450855414",
"policy_data": "{\"bindings\":[{\"members\":[\"allUsers\"],\"role\":\"roles/run.invoker\"}]}"
},
"sensitive_attributes": []
}
]
},
{
"mode": "managed",
"type": "google_cloud_run_service",
"name": "latam_challenge_service",
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
"instances": [
{
"schema_version": 2,
"attributes": {
"autogenerate_revision_name": false,
"id": "locations/us-central1/namespaces/florencia-tryolabs-latam/services/latam-challenge",
"location": "us-central1",
"metadata": [
{
"annotations": {},
"effective_annotations": {
"run.googleapis.com/ingress": "all",
"run.googleapis.com/ingress-status": "all",
"run.googleapis.com/operation-id": "798e9ce8-f9a8-4c27-a595-6ab85ec73a63",
"serving.knative.dev/creator": "florencia@tryolabs.com",
"serving.knative.dev/lastModifier": "florencia@tryolabs.com"
},
"effective_labels": {
"cloud.googleapis.com/location": "us-central1"
},
"generation": 1,
"labels": {},
"namespace": "florencia-tryolabs-latam",
"resource_version": "AAYbzoRf3lE",
"self_link": "/apis/serving.knative.dev/v1/namespaces/307648342667/services/latam-challenge",
"terraform_labels": {},
"uid": "22637102-e0fa-49ea-8643-85dfc7604be4"
}
],
"name": "latam-challenge",
"project": "florencia-tryolabs-latam",
"status": [
{
"conditions": [
{
"message": "",
"reason": "",
"status": "True",
"type": "Ready"
},
{
"message": "",
"reason": "",
"status": "True",
"type": "ConfigurationsReady"
},
{
"message": "",
"reason": "",
"status": "True",
"type": "RoutesReady"
}
],
"latest_created_revision_name": "latam-challenge-00001-xqz",
"latest_ready_revision_name": "latam-challenge-00001-xqz",
"observed_generation": 1,
"traffic": [
{
"latest_revision": true,
"percent": 100,
"revision_name": "latam-challenge-00001-xqz",
"tag": "",
"url": ""
}
],
"url": "https://latam-challenge-7eedzyco2q-uc.a.run.app"
}
],
"template": [
{
"metadata": [
{
"annotations": {
"autoscaling.knative.dev/maxScale": "100"
},
"generation": 0,
"labels": {
"run.googleapis.com/startupProbeType": "Default"
},
"name": "",
"namespace": "",
"resource_version": "",
"self_link": "",
"uid": ""
}
],
"spec": [
{
"container_concurrency": 80,
"containers": [
{
"args": null,
"command": null,
"env": [],
"env_from": [],
"image": "us-docker.pkg.dev/florencia-tryolabs-latam/florencia-repo-latam-challenge/latam-challenge",
"liveness_probe": [],
"name": "",
"ports": [
{
"container_port": 8000,
"name": "http1",
"protocol": ""
}
],
"resources": [
{
"limits": {
"cpu": "1000m",
"memory": "512Mi"
},
"requests": {}
}
],
"startup_probe": [
{
"failure_threshold": 1,
"grpc": [],
"http_get": [],
"initial_delay_seconds": 0,
"period_seconds": 240,
"tcp_socket": [
{
"port": 8000
}
],
"timeout_seconds": 240
}
],
"volume_mounts": [],
"working_dir": ""
}
],
"service_account_name": "307648342667-compute@developer.gserviceaccount.com",
"serving_state": "",
"timeout_seconds": 300,
"volumes": []
}
]
}
],
"timeouts": null,
"traffic": [
{
"latest_revision": true,
"percent": 100,
"revision_name": "",
"tag": "",
"url": ""
}
]
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxMjAwMDAwMDAwMDAwLCJkZWxldGUiOjEyMDAwMDAwMDAwMDAsInVwZGF0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMiJ9"
}
]
},
{
"mode": "managed",
"type": "google_cloud_run_service_iam_policy",
"name": "noauth",
"provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"etag": "BwYbzoS1QOI=",
"id": "v1/projects/florencia-tryolabs-latam/locations/us-central1/services/latam-challenge",
"location": "us-central1",
"policy_data": "{\"bindings\":[{\"members\":[\"allUsers\"],\"role\":\"roles/run.invoker\"}]}",
"project": "florencia-tryolabs-latam",
"service": "v1/projects/florencia-tryolabs-latam/locations/us-central1/services/latam-challenge"
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"data.google_iam_policy.noauth",
"google_cloud_run_service.latam_challenge_service"
]
}
]
}
],
"check_results": null
}
Loading

0 comments on commit 03a4881

Please sign in to comment.