Skip to content

feat: Automatic layer releases #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9fabeaa
feat: Copy gitlab-ci from datadog-lambda-js
astuyve Feb 28, 2024
13a3dd1
feat: first crack at migration the build script for individual publis…
astuyve Feb 29, 2024
9c75e09
feat: secrets for python. TODO - actually create them
astuyve Feb 29, 2024
6df517e
feat: Add python runtimes
astuyve Feb 29, 2024
e79dce6
feat: re-organize architecture flags. Support separate arch/name
astuyve Feb 29, 2024
a8e3a7b
feat: first draft of build generator template
astuyve Feb 29, 2024
ebd1a19
feat: Add datasources and first cut at publish_pypi script
astuyve Feb 29, 2024
38325c3
feat: oops, no node. TODO: fix container names
astuyve Feb 29, 2024
bd275aa
feat: pass the right layer name to sign layers
astuyve Feb 29, 2024
032ba8b
feat: Python before script
astuyve Feb 29, 2024
c7757fc
feat: arch parameterized sign layer
astuyve Feb 29, 2024
8223bcd
feat: fix up runtimes
astuyve Feb 29, 2024
74ef778
fix: build layer arch
astuyve Feb 29, 2024
2e6bab1
fix: Check layer size arch
astuyve Feb 29, 2024
f162f1d
feat: zip file is py not python
astuyve Feb 29, 2024
2d74327
fix: fix up check layer size script
astuyve Feb 29, 2024
d73ffb5
hotfix: use js ssm secrets until I can figure out which AWS account C…
astuyve Feb 29, 2024
9a0a1d8
feat: Less uniformity on images in python, specify in runtimes.yaml
astuyve Feb 29, 2024
8c8aad8
feat: Can't use permissions across repos
astuyve Mar 1, 2024
3a1f8de
feat: lol our ci runners set DD_SERVICE so it breaks our unit tests
astuyve Mar 1, 2024
e981cf7
feat: Gotta add yarn so we can add serverless
astuyve Mar 1, 2024
d770904
feat: lint
astuyve Mar 1, 2024
05e81c5
feat: Break install-node into separate task
astuyve Mar 1, 2024
748865d
feat: Use name instead of python_version
astuyve Mar 1, 2024
43dec9f
fix: no python-, just the version number
astuyve Mar 1, 2024
57603c1
empty commit to bump CI
astuyve Mar 1, 2024
bd0132e
feat: integration tests should run for both architectures
astuyve Mar 1, 2024
34ca5d7
fix: arg, no arch in integration test
astuyve Mar 1, 2024
29c194a
fix: pass sls framework the proper arch
astuyve Mar 1, 2024
54c9174
feat: fix script
astuyve Mar 1, 2024
dfd426b
feat: Default to x86 just so the invoke function works
astuyve Mar 1, 2024
264964f
fix: nvm pass the sls arch everywhere I guess
astuyve Mar 1, 2024
01a0119
fix: strip arch from user agent
astuyve Mar 1, 2024
d1b2313
feat: the right x86_64 arch for serverless framework
astuyve Mar 1, 2024
92b8108
fix: globalize local env
astuyve Mar 1, 2024
960fead
feat: fix regex
astuyve Mar 1, 2024
8283354
fix: ints should pass now
astuyve Mar 1, 2024
03826ca
feat: Update tests
astuyve Mar 2, 2024
04620c9
fix: lint
astuyve Mar 2, 2024
9d3d3de
fix: lint
astuyve Mar 2, 2024
251d27a
feat: lint
astuyve Mar 2, 2024
192ba0a
feat: I think we just need one lint
astuyve Mar 2, 2024
acc89c9
feat: remove install node for publish step
astuyve Mar 2, 2024
529a851
feat: remove integration tests from github build, we run them in gitl…
astuyve Mar 4, 2024
22a18da
feat: token applied
astuyve Mar 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,74 +63,3 @@ jobs:
run: |
source venv/bin/activate
pytest -vv

integration-test:
runs-on: ubuntu-latest
strategy:
matrix:
runtime-param: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node 14
uses: actions/setup-node@v3
with:
node-version: 14

- name: Cache Node modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Python dependencies
run: |
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install .[dev]

- name: Install Serverless Framework
run: sudo yarn global add serverless@^3.7.0 --prefix /usr/local
- name: Install Crossbuild Deps
run: |
sudo apt-get update --allow-releaseinfo-change --fix-missing
sudo apt install -y qemu-user-static binfmt-support

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: tests/integration
run: yarn install

- name: Run tests
env:
BUILD_LAYERS: true
DD_API_KEY: ${{ secrets.DD_API_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
RUNTIME_PARAM: ${{ matrix.runtime-param }}
run: ./scripts/run_integration_tests.sh

- name: Send success metric
env:
DD_API_KEY: ${{ secrets.DD_API_KEY }}
run: ./scripts/send_status_metric.sh 0 $DD_API_KEY

integration-test-failure:
runs-on: ubuntu-latest
needs: [integration-test]
if: always() && (needs.integration-test.result == 'failure')
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Send a failure metric
env:
DD_API_KEY: ${{ secrets.DD_API_KEY }}
run: ./scripts/send_status_metric.sh 1 $DD_API_KEY
29 changes: 29 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
stages:
- pre
- build

.go-cache: &go-cache
key: datadog-lambda-python-go-cache
policy: pull

generator:
stage: pre
image: registry.ddbuild.io/images/mirror/golang:alpine
tags: ["arch:amd64"]
cache: *go-cache
script:
- apk add --no-cache gomplate
- gomplate --config ci/config.yaml
artifacts:
paths:
- ci/*-pipeline.yaml

build-layers:
stage: build
trigger:
include:
- artifact: ci/build-pipeline.yaml
job: generator
strategy: depend
rules:
- when: on_success
13 changes: 13 additions & 0 deletions ci/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
inputFiles:
- ci/input_files/build.yaml.tpl

outputFiles:
- ci/build-pipeline.yaml

datasources:
runtimes:
url: ci/datasources/runtimes.yaml
regions:
url: ci/datasources/regions.yaml
environments:
url: ci/datasources/environments.yaml
9 changes: 9 additions & 0 deletions ci/datasources/environments.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
environments:
- name: sandbox
external_id: sandbox-publish-externalid
role_to_assume: sandbox-layer-deployer
account: 425362996713
- name: prod
external_id: prod-publish-externalid
role_to_assume: dd-serverless-layer-deployer-role
account: 464622532012
29 changes: 29 additions & 0 deletions ci/datasources/regions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
regions:
- code: "us-east-1"
- code: "us-east-2"
- code: "us-west-1"
- code: "us-west-2"
- code: "af-south-1"
- code: "ap-east-1"
- code: "ap-south-1"
- code: "ap-south-2"
- code: "ap-southeast-1"
- code: "ap-southeast-2"
- code: "ap-southeast-3"
- code: "ap-southeast-4"
- code: "ap-northeast-1"
- code: "ap-northeast-2"
- code: "ap-northeast-3"
- code: "ca-central-1"
# - code: "ca-west-1" we don't support it
- code: "eu-central-1"
- code: "eu-central-2"
- code: "eu-west-1"
- code: "eu-west-2"
- code: "eu-west-3"
- code: "eu-south-1"
- code: "eu-south-2"
# - code: "il-central-1" we don't support it
- code: "me-south-1"
- code: "me-central-1"
- code: "sa-east-1"
41 changes: 41 additions & 0 deletions ci/datasources/runtimes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
runtimes:
- name: "python38"
python_version: "3.8"
arch: "amd64"
image: "3.8"
- name: "python38"
python_version: "3.8"
arch: "arm64"
image: "3.8"
- name: "python39"
python_version: "3.8"
arch: "amd64"
image: "3.9"
- name: "python39"
python_version: "3.9"
arch: "arm64"
image: "3.9"
- name: "python310"
python_version: "3.10"
arch: "amd64"
image: "3.10"
- name: "python310"
python_version: "3.10"
arch: "arm64"
image: "3.10"
- name: "python311"
python_version: "3.11"
arch: "amd64"
image: "3.11.6"
- name: "python311"
python_version: "3.11"
arch: "arm64"
image: "3.11.6"
- name: "python312"
python_version: "3.12"
arch: "amd64"
image: "3.12.0"
- name: "python312"
python_version: "3.12"
arch: "arm64"
image: "3.12.0"
48 changes: 48 additions & 0 deletions ci/get_secrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2023 Datadog, Inc.

set -e

if [ -z "$EXTERNAL_ID_NAME" ]; then
printf "[Error] No EXTERNAL_ID_NAME found.\n"
printf "Exiting script...\n"
exit 1
fi

if [ -z "$ROLE_TO_ASSUME" ]; then
printf "[Error] No ROLE_TO_ASSUME found.\n"
printf "Exiting script...\n"
exit 1
fi

printf "Getting AWS External ID...\n"

EXTERNAL_ID=$(aws ssm get-parameter \
--region us-east-1 \
--name "ci.datadog-lambda-python.$EXTERNAL_ID_NAME" \
--with-decryption \
--query "Parameter.Value" \
--out text)

printf "Getting DD API KEY...\n"

export DD_API_KEY=$(aws ssm get-parameter \
--region us-east-1 \
--name ci.datadog-lambda-python.dd-api-key \
--with-decryption \
--query "Parameter.Value" \
--out text)

printf "Assuming role...\n"

export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \
$(aws sts assume-role \
--role-arn "arn:aws:iam::$AWS_ACCOUNT:role/$ROLE_TO_ASSUME" \
--role-session-name "ci.datadog-lambda-python-$CI_JOB_ID-$CI_JOB_STAGE" \
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \
--external-id $EXTERNAL_ID \
--output text))
Loading