GithubHelp home page GithubHelp logo

dove6 / tbd-workshop-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bdg-tbd/tbd-workshop-1

0.0 0.0 0.0 2.39 MB

TBD workshop 1

License: Apache License 2.0

Shell 13.35% Python 2.01% XSLT 0.63% HCL 11.72% Jupyter Notebook 70.12% Dockerfile 2.17%

tbd-workshop-1's Introduction

TBD Workshop 1.

dddd

Workshop goals

  1. Learn how to provision computing resources for running Big Data analyses using the Infrastructure as Code (IaC) approach.
  2. Learn how to set up opinionated CI/CD pipelines to deploy cloud infrastructure.
  3. Learn how to utilize linters for detecting security vulnerabilities in cloud infrastructure.
  4. Learn how to run Apache Spark code in a distributed way on Hadoop cluster using Vertex AI notebooks and Dataproc services on GCP.
  5. Learn how to use Workload Identity Federation for a secure authentication from GitHub Actions to Google Cloud. img.png

High level architecture

img.png

Prerequisites

Software

GCP

  • Redeem a GCP coupon to create a billing account
  • Authenticate to GCP to obtain the default credentials used for running the code
# first remove the stored credentials if exist
gcloud auth application-default revoke
# login and get the new application credentials
gcloud auth application-default login

Project setup

  1. Export shared environment variables
export TF_VAR_tbd_semester=2024L
# format: 20xx for teachers, student ID number for students 
export TF_VAR_user_id=9900
# use your own billing account id
export TF_VAR_billing_account=01F44C-CA9C7E-587C25
  1. Enter bootstrap folder then init project and Terraform state bucket
cd bootstrap
terraform init
terraform apply
cd ..
  1. CI/CD (Github Actions setup using Workload Identity Federation)
  • Edit env/backend.tfvars file and set bucket variable with the Terraform state bucket
  • Edit env/project.tfvars file and set project_name, iac_service_account variables using the output from the bootstrap phase, e.g.: img.png
  • Edit cicd_bootstrap/conf/github_actions.tfvars to set github_org and github_repo, e.g.:
  github_org  = "mwiewior"
  github_repo = "tbd-workshop-1"
  • Init state file and set env variables
cd cicd_bootstrap
terraform init -backend-config=../env/backend.tfvars
  • Apply
# authenticate Docker backend with GCP
gcloud auth configure-docker
# create CI/CD integration using Workload Identity
terraform apply -var-file ../env/project.tfvars -var-file conf/github_actions.tfvars -compact-warnings
cd ..
  1. Use output variables for configuring Github Actions workflow: .github/workflows/pull-request.yml,e.g. : img.png Please do not edit and hardcode these values in a YAML but set the Github Actions secrets instead while preserving the secret names, i.e. GCP_WORKLOAD_IDENTITY_PROVIDER_NAME and GCP_WORKLOAD_IDENTITY_SA_EMAIL. img.png
  2. Install and configure pre-commit
pre-commit install
  1. Commit changes, push to a branch and open a PR to YOUR repository main/master branch. If you see a warning like this -- please enable the workflows: img.png ...and repush your changes!

Once all Pull Requests checks have passed please merge your PR and wait until your release job finishes. 7. Navigate to the Vertex AI Workbench menu item, find your notebook on the list, press CONNECT and follow the instructions img.png

  1. Check if pyspark kernel exists - if not then in your Jupyterlab enviroment add Python3.8 kernel:
python3.8 -m ipykernel install --user --name pyspark
  1. Run a Hello-world PySpark application in a YARN-client mode: img.png

  2. Additional tasks using Terraform:

  1. Add support for arbitrary machine types and worker nodes for a Dataproc cluster and JupyterLab instance
  2. Add support for preemptible/spot instances in a Dataproc cluster
  3. Perform additional hardening of Jupyterlab environment, i.e. disable sudo access and enable secure boot
  4. (Optional) Get access to Apache Spark WebUI
  1. Create a BigQuery dataset and an external table (change storage location if needed)
CREATE SCHEMA IF NOT EXISTS demo OPTIONS(location = 'europe-west1');

CREATE OR REPLACE EXTERNAL TABLE demo.shakespeare
  OPTIONS (
  
  format = 'ORC',
  uris = ['gs://tbd-2023z-9900-data/data/shakespeare/*.orc']);


SELECT * FROM demo.shakespeare ORDER BY sum_word_count DESC LIMIT 5;
  1. Workshop 2 exercises are described in Jupyter notebook

  2. IMPORTANT ❗ ❗ ❗ Please remember to destroy all the resources after the workshop:

terraform init -backend-config=env/backend.tfvars
terraform destroy -no-color -var-file env/project.tfvars 

Requirements

Name Version
terraform ~> 1.5.0
docker 3.0.2
google ~> 5.23.0
kubernetes 2.24.0

Providers

Name Version
google 5.23.0
kubernetes 2.24.0

Modules

Name Source Version
composer ./modules/composer n/a
data-pipelines ./modules/data-pipeline n/a
dataproc ./modules/dataproc n/a
dbt_docker_image ./modules/dbt_docker_image n/a
gcr ./modules/gcr n/a
jupyter_docker_image ./modules/jupyter_docker_image n/a
vertex_ai_workbench ./modules/vertex-ai-workbench n/a
vpc ./modules/vpc n/a

Resources

Name Type
google_compute_firewall.allow-all-internal resource
kubernetes_service.dbt-task-service resource
google_client_config.provider data source
google_container_cluster.composer-gke-cluster data source

Inputs

Name Description Type Default Required
ai_notebook_instance_owner Vertex AI workbench owner string n/a yes
project_name Project name string n/a yes
region GCP region string "europe-west1" no

Outputs

No outputs.

tbd-workshop-1's People

Contributors

mwiewior avatar dove6 avatar chebawca21 avatar tgambin avatar miniaczq avatar sitekwb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.