Skip to content

Commit 33c1069

Browse files
author
MB Burch
authored
Merge pull request #32 from ConductorOne/mbburch/bb-733-lambda-prep
Update for containerization
2 parents 6a114d3 + 8f239d1 commit 33c1069

File tree

8 files changed

+147
-8
lines changed

8 files changed

+147
-8
lines changed

.github/workflows/release.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ jobs:
3434
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
3535
AC_PROVIDER: ${{ secrets.AC_PROVIDER }}
3636
goreleaser-docker:
37+
permissions:
38+
id-token: write
39+
contents: read
3740
runs-on: ubuntu-latest
3841
steps:
42+
- name: Configure AWS credentials
43+
uses: aws-actions/configure-aws-credentials@v4
44+
with:
45+
role-to-assume: arn:aws:iam::168442440833:role/GitHubActionsECRPushRole-baton-postgresql
46+
aws-region: us-west-2
47+
- name: Login to Amazon ECR
48+
uses: aws-actions/amazon-ecr-login@v2
3949
- name: Checkout
4050
uses: actions/checkout@v4
4151
with:

.goreleaser.docker.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ builds:
1111
goarch:
1212
- amd64
1313
- arm64
14+
tags:
15+
- "baton_lambda_support"
1416
dockers:
1517
- use: buildx
1618
goos: linux
@@ -38,6 +40,19 @@ dockers:
3840
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
3941
- "--label=org.opencontainers.image.version={{.Version}}"
4042
- "--label=org.opencontainers.image.source=https://github.com/conductorone/baton-postgresql"
43+
- use: buildx
44+
goos: linux
45+
goarch: arm64
46+
dockerfile: Dockerfile.lambda
47+
image_templates:
48+
- "168442440833.dkr.ecr.us-west-2.amazonaws.com/baton-postgresql:{{ .Version }}-arm64"
49+
build_flag_templates:
50+
- "--platform=linux/arm64/v8"
51+
- "--label=org.opencontainers.image.created={{.Date}}"
52+
- "--label=org.opencontainers.image.title=baton-postgresql"
53+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
54+
- "--label=org.opencontainers.image.version={{.Version}}"
55+
- "--label=org.opencontainers.image.source=https://github.com/conductorone/baton-postgresql"
4156
docker_manifests:
4257
- name_template: ghcr.io/conductorone/baton-postgresql:{{ .Version }}
4358
image_templates:

Dockerfile.lambda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM public.ecr.aws/lambda/provided:al2023
2+
ENTRYPOINT ["/baton-postgresql", "lambda"]
3+
COPY baton-postgresql /

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
GOOS = $(shell go env GOOS)
22
GOARCH = $(shell go env GOARCH)
33
BUILD_DIR = dist/${GOOS}_${GOARCH}
4+
GENERATED_CONF = pkg/config/conf.gen.go
45

56
ifeq ($(GOOS),windows)
67
OUTPUT_PATH = ${BUILD_DIR}/baton-postgresql.exe
78
else
89
OUTPUT_PATH = ${BUILD_DIR}/baton-postgresql
910
endif
1011

12+
# Set the build tag conditionally based on BATON_LAMBDA_SUPPORT
13+
ifdef BATON_LAMBDA_SUPPORT
14+
BUILD_TAGS=-tags baton_lambda_support
15+
else
16+
BUILD_TAGS=
17+
endif
18+
1119
.PHONY: build
12-
build:
13-
go build -o ${OUTPUT_PATH} ./cmd/baton-postgresql
20+
build: $(GENERATED_CONF)
21+
go build ${BUILD_TAGS} -o ${OUTPUT_PATH} ./cmd/baton-postgresql
22+
23+
$(GENERATED_CONF): pkg/config/config.go go.mod
24+
@echo "Generating $(GENERATED_CONF)..."
25+
go generate ./pkg/config
26+
27+
generate: $(GENERATED_CONF)
1428

1529
.PHONY: update-deps
1630
update-deps:

cmd/baton-postgresql/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"fmt"
66
"os"
77

8+
cfg "github.com/conductorone/baton-postgresql/pkg/config"
89
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
910
"github.com/conductorone/baton-sdk/pkg/types"
1011
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
11-
"github.com/spf13/viper"
1212
"go.uber.org/zap"
1313

1414
"github.com/conductorone/baton-postgresql/pkg/connector"
@@ -20,7 +20,7 @@ var version = "dev"
2020
func main() {
2121
ctx := context.Background()
2222

23-
_, cmd, err := configschema.DefineConfiguration(ctx, "baton-postgresql", getConnector, configuration)
23+
_, cmd, err := configschema.DefineConfiguration(ctx, "baton-postgresql", getConnector, cfg.Config)
2424
if err != nil {
2525
fmt.Fprintln(os.Stderr, err.Error())
2626
os.Exit(1)
@@ -35,10 +35,10 @@ func main() {
3535
}
3636
}
3737

38-
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
38+
func getConnector(ctx context.Context, pgc *cfg.Postgresql) (types.ConnectorServer, error) {
3939
l := ctxzap.Extract(ctx)
4040

41-
cb, err := connector.New(ctx, v.GetString("dsn"), v.GetStringSlice("schemas"), v.GetBool("include-columns"), v.GetBool("include-large-objects"))
41+
cb, err := connector.New(ctx, pgc.Dsn, pgc.Schemas, pgc.IncludeColumns, pgc.IncludeLargeObjects)
4242
if err != nil {
4343
l.Error("error creating connector", zap.Error(err))
4444
return nil, err

pkg/config/conf.gen.go

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package config
22

33
import (
44
"github.com/conductorone/baton-sdk/pkg/field"
@@ -13,6 +13,7 @@ var (
1313

1414
var relationships = []field.SchemaFieldRelationship{}
1515

16-
var configuration = field.NewConfiguration([]field.SchemaField{
16+
//go:generate go run ./gen
17+
var Config = field.NewConfiguration([]field.SchemaField{
1718
dsn, schemas, includeColumns, includeLargeObjects,
1819
}, relationships...)

pkg/config/gen/gen.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
cfg "github.com/conductorone/baton-postgresql/pkg/config"
5+
"github.com/conductorone/baton-sdk/pkg/config"
6+
)
7+
8+
func main() {
9+
config.Generate("postgresql", cfg.Config)
10+
}

0 commit comments

Comments
 (0)