-
Notifications
You must be signed in to change notification settings - Fork 9
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 #8 from KishinNext/release-candidate/dagger
Release candidate/dagger
- Loading branch information
Showing
19 changed files
with
899 additions
and
813 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,51 @@ | ||
name: 'ci' | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
dagger: | ||
runs-on: ubuntu-latest | ||
env: | ||
PROJECT_ID: prod-datascience-393718 | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
uses: 'google-github-actions/auth@v1' | ||
with: | ||
token_format: 'access_token' | ||
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' | ||
- | ||
name: Login to Google Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: gcr.io | ||
username: oauth2accesstoken | ||
password: ${{ steps.auth.outputs.access_token }} | ||
- | ||
name: Set up Cloud SDK | ||
uses: google-github-actions/setup-gcloud@v1 | ||
with: | ||
project_id: ${{ env.PROJECT_ID }} | ||
- | ||
name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
- | ||
name: Install | ||
run: pip install dagger-io google-cloud-run | ||
|
||
- | ||
name: Copy development.yml on workspace | ||
run: gcloud storage cp gs://prod-datascience-393718_cloudbuild/development.yaml config/. | ||
|
||
- | ||
name: Release and deploy with Dagger | ||
run: python ci/main.py |
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,4 +1,4 @@ | ||
FROM python:3.9.16-slim-buster as base | ||
FROM python:3.10-slim-buster as base | ||
|
||
WORKDIR /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
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
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,78 @@ | ||
import sys | ||
|
||
import anyio | ||
from google.cloud import run_v2 | ||
import os | ||
import dagger | ||
|
||
PROJECT = 'prod-datascience-393718' | ||
GCR_SERVICE_URL = f"projects/{PROJECT}/locations/us-central1/services/querycraftergg" | ||
GCR_PUBLISH_ADDRESS = f"gcr.io/{PROJECT}/querycrafter" | ||
|
||
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
async def main(): | ||
version = '3.10' | ||
|
||
async with dagger.Connection(dagger.Config(log_output=sys.stderr)) as client: | ||
app = client.host().directory(root) # Asegúrate de cambiar esto a la ruta real de tu código | ||
|
||
python_container = ( | ||
client.container(platform=dagger.Platform("linux/amd64")).from_(f"python:{version}-slim-buster")) | ||
container = ( | ||
python_container.with_directory("/app", app) | ||
.with_workdir("/app") | ||
.with_exec(["pip", "install", "poetry"]) | ||
.with_exec(["poetry", "config", "virtualenvs.create", "false"]) | ||
.with_exec(["poetry", "install", "--no-interaction", "--no-ansi"]) | ||
.with_exec(["pytest"]) | ||
.with_exposed_port(8080) | ||
.with_entrypoint(["python", "-m", "app"]) | ||
) | ||
|
||
# publish the container to GCR object | ||
container_image = await container.publish(GCR_PUBLISH_ADDRESS) | ||
print(f"Container published to {container_image}.") | ||
|
||
gcr_client = run_v2.ServicesClient() | ||
|
||
# define a service request | ||
gcr_request = run_v2.UpdateServiceRequest( | ||
service=run_v2.Service( | ||
name=GCR_SERVICE_URL, | ||
template=run_v2.RevisionTemplate( | ||
containers=[ | ||
run_v2.Container( | ||
image=container_image, | ||
ports=[ | ||
run_v2.ContainerPort( | ||
name="http1", | ||
container_port=8080, | ||
), | ||
], | ||
startup_probe=run_v2.Probe( # Agregando el health check aquí | ||
initial_delay_seconds=30, | ||
period_seconds=5, | ||
http_get=run_v2.HTTPGetAction( | ||
path="/healthcheck", | ||
port=8080 | ||
) | ||
), | ||
), | ||
], | ||
), | ||
) | ||
) | ||
# update service | ||
gcr_operation = gcr_client.update_service(request=gcr_request) | ||
print("GCP service update request sent.") | ||
|
||
# wait for service request completion | ||
response = gcr_operation.result() | ||
print("GCP service update request completed.") | ||
|
||
print(f"Deployment for image {container_image} now available at {response}.") | ||
|
||
|
||
anyio.run(main) |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ logging: | |
level: INFO | ||
handlers: | ||
- console | ||
default_model_name: 'gpt-3.5-turbo-16k' |
Oops, something went wrong.