Skip to content

Commit

Permalink
ci: K8s deploy config (#2)
Browse files Browse the repository at this point in the history
* build: init helm charts

* build: add delta prod dockerfile

* fix: preserve line breaks in echo

* build: enable build cache

* fix: k8s health checks

* build: use sed instead of whole env substitution

* ci: add azure pipelines
  • Loading branch information
Kenneth Domingo authored Nov 13, 2023
1 parent fdd8131 commit 1ae013e
Show file tree
Hide file tree
Showing 41 changed files with 1,350 additions and 22 deletions.
163 changes: 163 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

infra/
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
DELTA_BEARER_TOKEN="<openssl rand -base64 32>"
SAS_TOKEN="get from Azure portal"
STORAGE_ACCESS_KEY="get from Azure portal"
STORAGE_ACCOUNT_NAME=
CONTAINER_NAME=
DELTA_SHARING_HOST="sharing-server:8890"

DATA_SHARING_PROXY_IMAGE_REPOSITORY=
DATA_SHARING_DELTA_IMAGE_REPOSITORY=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ cython_debug/

.task/
conf/
secrets.yaml
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repos:
args: [ '--fix=lf' ]
- id: check-merge-conflict
- id: check-yaml
exclude: infra/helm/.+/templates/.+
- repo: https://github.com/zricethezav/gitleaks
rev: v8.18.0
hooks:
Expand Down
69 changes: 59 additions & 10 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ dotenv:
- .env

vars:
NAME: giga-dataops_data-sharing
PROJECT_NAME: giga-dataops_data-sharing
SHORT_SHA:
sh: git rev-parse --short HEAD

tasks:
default:
desc: Build and start Docker containers
cmds:
- task: config
- docker compose --project-name giga-dataops-platform --file docker-compose-network.yaml up --detach --build --remove-orphans {{.CLI_ARGS}}
- docker compose --project-name {{.NAME}} up --detach --build --remove-orphans {{.CLI_ARGS}}
- docker compose --project-name {{.PROJECT_NAME}} up --detach --build --remove-orphans {{.CLI_ARGS}}

setup:
desc: Run initial setup
Expand All @@ -32,35 +34,82 @@ tasks:
cmds:
- mkdir -p conf
- >
sed 's|{{`{{.STORAGE_ACCESS_KEY}}`}}|{{.STORAGE_ACCESS_KEY}}|'
sed -e 's|{{`{{.STORAGE_ACCESS_KEY}}`}}|{{.STORAGE_ACCESS_KEY}}|'
-e 's|{{`{{.STORAGE_ACCOUNT_NAME}}`}}|{{.STORAGE_ACCOUNT_NAME}}|'
conf-template/core-site.xml > conf/core-site.xml
- >
sed 's!{{`{{.DELTA_BEARER_TOKEN}}`}}!{{.DELTA_BEARER_TOKEN}}!'
conf-template/delta-sharing-server-config.yml > conf/delta-sharing-server-config.yml
sed -e 's!{{`{{.DELTA_BEARER_TOKEN}}`}}!{{.DELTA_BEARER_TOKEN}}!'
-e 's!{{`{{.STORAGE_ACCOUNT_NAME}}`}}!{{.STORAGE_ACCOUNT_NAME}}!'
-e 's!{{`{{.CONTAINER_NAME}}`}}!{{.CONTAINER_NAME}}!'
conf-template/delta-sharing-server.yaml > conf/delta-sharing-server.yaml
logs:
desc: Attach to Docker logs
cmds:
- docker compose --project-name {{.NAME}} logs --follow {{.CLI_ARGS}}
- docker compose --project-name {{.PROJECT_NAME}} logs --follow {{.CLI_ARGS}}

stop:
desc: Stop containers
cmds:
- docker compose --project-name {{.NAME}} stop {{.CLI_ARGS}}
- docker compose --project-name {{.PROJECT_NAME}} stop {{.CLI_ARGS}}

restart:
desc: Restart containers
cmds:
- task: config
- docker compose --project-name {{.NAME}} restart {{.CLI_ARGS}}
- docker compose --project-name {{.PROJECT_NAME}} restart {{.CLI_ARGS}}

exec:
desc: Run a command in the specified container
cmds:
- docker compose --project-name {{.NAME}} exec {{.CLI_ARGS}}
- docker compose --project-name {{.PROJECT_NAME}} exec {{.CLI_ARGS}}

clean:
desc: Remove containers
cmds:
- docker compose --project-name {{.NAME}} down --volumes --remove-orphans {{.CLI_ARGS}}
- docker compose --project-name {{.PROJECT_NAME}} down --volumes --remove-orphans {{.CLI_ARGS}}
- docker compose --project-name giga-dataops-platform --file docker-compose-network.yaml down --volumes --remove-orphans {{.CLI_ARGS}}

build-and-push:
desc: Build and push Docker image
cmds:
- task: build
- task: push

build:
internal: true
desc: Build Docker image
cmds:
- docker build --tag {{.DATA_SHARING_PROXY_IMAGE_REPOSITORY}}:{{.SHORT_SHA}} -f proxy.prod.Dockerfile .
- docker build --tag {{.DATA_SHARING_DELTA_IMAGE_REPOSITORY}}:{{.SHORT_SHA}} -f delta.prod.Dockerfile .

push:
internal: true
desc: Push Docker image
cmds:
- docker push {{.DATA_SHARING_PROXY_IMAGE_REPOSITORY}}:{{.SHORT_SHA}}
- docker push {{.DATA_SHARING_DELTA_IMAGE_REPOSITORY}}:{{.SHORT_SHA}}

helm-up:
desc: Install/upgrade Helm chart
dir: infra
cmds:
- kubectl apply -f k8s/configmap.yaml
- kubectl apply -f k8s/secrets.yaml
- >
helm upgrade --install data-sharing-delta ./helm/data-sharing-delta
--set image.repository={{.DATA_SHARING_DELTA_IMAGE_REPOSITORY}}
--set image.tag={{.SHORT_SHA}}
- >
helm upgrade --install data-sharing-proxy ./helm/data-sharing-proxy
--set image.repository={{.DATA_SHARING_PROXY_IMAGE_REPOSITORY}}
--set image.tag={{.SHORT_SHA}}
helm-down:
desc: Uninstall Helm chart
dir: infra/helm
cmds:
- helm uninstall data-sharing-proxy
- helm uninstall data-sharing-delta
- kubectl delete all --all
- kubectl delete pvc --all
52 changes: 52 additions & 0 deletions azure/azure-pipelines-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
trigger:
branches:
include:
- main

pr: none

pool:
vmImage: ubuntu-latest

variables:
kubernetesServiceConnection: $(KUBERNETES_SERVICE_CONNECTION)
kubernetesNamespace: $(KUBERNETES_NAMESPACE)
system.debug: true

steps:
- task: HelmDeploy@0
displayName: Helm uninstall Data Sharing proxy
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(kubernetesServiceConnection)
namespace: $(kubernetesNamespace)
command: uninstall
arguments: data-sharing-proxy

- task: HelmDeploy@0
displayName: Helm uninstall Data Sharing Delta
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(kubernetesServiceConnection)
namespace: $(kubernetesNamespace)
command: uninstall
arguments: data-sharing-delta

- task: Kubernetes@1
displayName: Delete resources in namespace
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(kubernetesServiceConnection)
command: delete
arguments: all --all
namespace: $(kubernetesNamespace)

- task: Kubernetes@1
displayName: Delete PVCs in namespace
continueOnError: true
inputs:
connectionType: Kubernetes Service Connection
kubernetesServiceEndpoint: $(kubernetesServiceConnection)
command: delete
arguments: pvc --all
namespace: $(kubernetesNamespace)
Loading

0 comments on commit 1ae013e

Please sign in to comment.