Skip to content
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

Add drone build job for lambda-promtail images. #4480

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 50 additions & 1 deletion .drone/drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ local secret(name, vault_path, vault_key) = {
};
local docker_username_secret = secret('docker_username', 'infra/data/ci/docker_hub', 'username');
local docker_password_secret = secret('docker_password', 'infra/data/ci/docker_hub', 'password');
local ecr_key = secret('ecr_key', 'infra/data/ci/loki/aws-credentials', 'access_key_id');
local ecr_secret_key = secret('ecr_secret_key', 'infra/data/ci/loki/aws-credentials', 'secret_access_key');
local pull_secret = secret('dockerconfigjson', 'secret/data/common/gcr', '.dockerconfigjson');
local github_secret = secret('github_token', 'infra/data/ci/github/grafanabot', 'pat');

Expand Down Expand Up @@ -73,6 +75,21 @@ local clients_docker(arch, app) = {
},
};

local lambda_promtail_ecr(app) = {
name: '%s-image' % if $.settings.dry_run then 'build-' + app else 'publish-' + app,
image: 'cstyan/ecr',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be grafana/ecr perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can move my fork of the ECR plugin + the docker image to grafana owned repos at any point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context: why isn't it that way already? Just testing for now?

privileged: true,
settings: {
repo: 'lambda-promtail',
registry: 'public.ecr.aws/grafana',
dockerfile: 'tools/%s/Dockerfile' % app,
access_key: { from_secret: ecr_key.name },
secret_key: { from_secret: ecr_secret_key.name },
dry_run: false,
DylanGuedes marked this conversation as resolved.
Show resolved Hide resolved
region: 'us-east-1',
},
};

local arch_image(arch, tags='') = {
platform: {
os: 'linux',
Expand Down Expand Up @@ -209,6 +226,37 @@ local promtail(arch) = pipeline('promtail-' + arch) + arch_image(arch) {
depends_on: ['check'],
};

local lambda_promtail(tags='') = pipeline('lambda-promtail'){
steps+: [
{
name: 'image-tag',
image: 'alpine',
commands: [
'apk add --no-cache bash git',
'git fetch origin --tags',
'echo $(./tools/image-tag)-amd64 > .tags',
] + if tags != '' then ['echo ",%s" >> .tags' % tags] else [],
},
lambda_promtail_ecr('lambda-promtail') {
depends_on: ['image-tag'],
when: condition('exclude').tagMain,
settings+: {
dry_run: true,
},
},
] + [
// publish for tag or main
lambda_promtail_ecr('lambda-promtail') {
depends_on: ['image-tag'],
when: condition('include').tagMain,
settings+: {
build_args: ['TOUCH_PROTOS=1'],
},
},
],
depends_on: ['check'],
};

local multiarch_image(arch) = pipeline('docker-' + arch) + arch_image(arch) {
steps+: [
// dry run for everything that is not tag or main
Expand Down Expand Up @@ -355,4 +403,5 @@ local manifest(apps) = pipeline('manifest') {
],
},
] + [promtail_win()]
+ [github_secret, pull_secret, docker_username_secret, docker_password_secret, deploy_configuration]
+ [lambda_promtail('latest,main')]
+ [github_secret, pull_secret, docker_username_secret, docker_password_secret, ecr_key, ecr_secret_key, deploy_configuration]
71 changes: 70 additions & 1 deletion .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,63 @@ steps:
image: golang:windowsservercore-1809
name: test
---
depends_on:
- check
kind: pipeline
name: lambda-promtail
steps:
- commands:
- apk add --no-cache bash git
- git fetch origin --tags
- echo $(./tools/image-tag)-amd64 > .tags
- echo ",latest,main" >> .tags
image: alpine
name: image-tag
- depends_on:
- image-tag
image: cstyan/ecr
name: build-lambda-promtail-image
privileged: true
settings:
access_key:
from_secret: ecr_key
dockerfile: tools/lambda-promtail/Dockerfile
dry_run: true
region: us-east-1
registry: public.ecr.aws/grafana
repo: lambda-promtail
secret_key:
from_secret: ecr_secret_key
when:
ref:
exclude:
- refs/heads/main
- refs/heads/k??
- refs/tags/v*
- depends_on:
- image-tag
image: cstyan/ecr
name: publish-lambda-promtail-image
privileged: true
settings:
access_key:
from_secret: ecr_key
build_args:
- TOUCH_PROTOS=1
dockerfile: tools/lambda-promtail/Dockerfile
dry_run: false
region: us-east-1
registry: public.ecr.aws/grafana
repo: lambda-promtail
secret_key:
from_secret: ecr_secret_key
when:
ref:
include:
- refs/heads/main
- refs/heads/k??
- refs/tags/v*
---
get:
name: pat
path: infra/data/ci/github/grafanabot
Expand All @@ -908,13 +965,25 @@ get:
kind: secret
name: docker_password
---
get:
name: access_key_id
path: infra/data/ci/loki/aws-credentials
kind: secret
name: ecr_key
---
get:
name: secret_access_key
path: infra/data/ci/loki/aws-credentials
kind: secret
name: ecr_secret_key
---
get:
name: config.json
path: infra/data/ci/loki/deploy
kind: secret
name: deploy_config
---
kind: signature
hmac: ad45dfe45de92130908844a1a3cf4b829d71e057f4c9f819063a437b963232d0
hmac: 2f519d332d5e2241a44b170461a9cf256dc8050de6d0a6caa99839a4b561aab5

...
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ ifeq ($(BUILD_IN_CONTAINER),true)
$(IMAGE_PREFIX)/loki-build-image:$(BUILD_IMAGE_VERSION) $@;
else
drone jsonnet --stream --format -V __build-image-version=$(BUILD_IMAGE_VERSION) --source .drone/drone.jsonnet --target .drone/drone.yml
drone lint .drone/drone.yml
drone lint .drone/drone.yml --trusted
drone sign --save grafana/loki .drone/drone.yml || echo "You must set DRONE_SERVER and DRONE_TOKEN"
endif

Expand Down
10 changes: 4 additions & 6 deletions tools/lambda-promtail/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
FROM golang:1-alpine3.12 AS build-image

WORKDIR /app
COPY tools/lambda-promtail /src/lambda-promtail
WORKDIR /src/lambda-promtail

RUN go version

RUN apk update && apk upgrade && \
apk add --no-cache bash git

COPY go.mod go.sum ./
RUN go mod download

COPY lambda-promtail/main.go main.go
RUN go build -tags lambda.norpc -ldflags="-s -w" main.go
RUN go build -tags lambda.norpc -ldflags="-s -w" lambda-promtail/main.go


FROM alpine:3.12

WORKDIR /app

COPY --from=build-image /app/main ./
COPY --from=build-image /src/lambda-promtail/main ./

ENTRYPOINT ["/app/main"]
3 changes: 0 additions & 3 deletions tools/lambda-promtail/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ all: build docker
build:
GOOS=linux CGO_ENABLED=0 go build lambda-promtail/main.go

docker:
docker build --pull .

clean:
rm main
5 changes: 2 additions & 3 deletions tools/lambda-promtail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ If you want to modify the lambda-promtail code you will also need:

### Building and Packaging

The provided Makefile has targets `build`, `docker`, `all`, and `clean`.
The provided Makefile has targets `build`, and `clean`.

`build`, `docker`, and `all` build the lambda-promtail as a Go static binary and use the AWS Lambda Go runtime base image to generate an image that you
can upload to your AWS ECR and use via Lambda. `clean` will remove the built Go binary.
`build` builds the lambda-promtail as a Go static binary. To build the container image properly you should run `docker build . -f tools/lambda-promtail/Dockerfile` from the root of the Loki repository,you can upload this image to your AWS ECR and use via Lambda. `clean` will remove the built Go binary.

### Packaging and deployment

Expand Down