Skip to content

Commit 7ad630c

Browse files
Merge pull request #9 from swift-serverless/feature/remove-web-hook-service
Remove BreezeLambdaWebHookService
2 parents cafc954 + e63ae7c commit 7ad630c

17 files changed

Lines changed: 447 additions & 342 deletions

.devcontainer/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Note: You can use any Debian/Ubuntu based image you want.
2+
FROM swift:6.2.0
3+
4+
# [Optional] Uncomment this section to install additional OS packages.
5+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
&& apt-get -y install --no-install-recommends make

.devcontainer/devcontainer.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-outside-of-docker-compose
3+
{
4+
"name": "Docker from Docker Compose",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
9+
// Use this environment variable if you need to bind mount your local source code into a new container.
10+
"remoteEnv": {
11+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
12+
},
13+
14+
"features": {
15+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
16+
"version": "latest",
17+
"enableNonRootDocker": "true",
18+
"moby": "true"
19+
},
20+
"ghcr.io/devcontainers/features/aws-cli:1": {}
21+
},
22+
23+
// Configure tool-specific properties.
24+
"customizations": {
25+
// Configure properties specific to VS Code.
26+
"vscode": {
27+
// Set *default* container specific settings.json values on container create.
28+
"settings": {
29+
"lldb.library": "/usr/lib/liblldb.so"
30+
},
31+
// Add the IDs of extensions you want installed when the container is created.
32+
"extensions": [
33+
"swiftlang.swift-vscode"
34+
]
35+
}
36+
}
37+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
38+
// "forwardPorts": [],
39+
40+
// Use 'postCreateCommand' to run commands after the container is created.
41+
// "postCreateCommand": "docker --version",
42+
43+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
44+
// "remoteUser": "root"
45+
}

.devcontainer/docker-compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
9+
volumes:
10+
# Forwards the local Docker socket to the container.
11+
- /var/run/docker.sock:/var/run/docker-host.sock
12+
# Update this to wherever you want VS Code to mount the folder of your project
13+
- ../..:/workspaces:cached
14+
15+
# Overrides default command so things don't shut down after the process ends.
16+
entrypoint: /usr/local/share/docker-init.sh
17+
depends_on:
18+
- localstack
19+
environment:
20+
- LOCALSTACK_ENDPOINT=http://localstack:4566
21+
- AWS_ACCESS_KEY_ID=test
22+
- AWS_SECRET_ACCESS_KEY=test
23+
- AWS_REGION=us-east-1
24+
command: sleep infinity
25+
26+
# Uncomment the next four lines if you will use a ptrace-based debuggers like C++, Go, and Rust.
27+
cap_add:
28+
- SYS_PTRACE
29+
security_opt:
30+
- seccomp:unconfined
31+
32+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
33+
# (Adding the "ports" property to this file will not forward from a Codespace.)
34+
localstack:
35+
image: localstack/localstack

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

.sourcekit-lsp/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/swiftlang/sourcekit-lsp/refs/heads/release/6.2/config.schema.json"
3+
}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ coverage:
2828
--instr-profile=$(SWIFT_BIN_PATH)/codecov/default.profdata \
2929
--format=lcov > $(GITHUB_WORKSPACE)/lcov.info
3030

31+
local_invoke_demo_app:
32+
curl -X POST 127.0.0.1:7000/invoke -H "Content-Type: application/json" -d @Tests/BreezeLambdaWebHookTests/Fixtures/get_webhook_api_gtw.json
33+
3134
preview_docc_lambda_api:
3235
swift package --disable-sandbox preview-documentation --target BreezeLambdaWebHook
3336

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
)
2020
],
2121
dependencies: [
22-
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.2.0"),
22+
.package(url: "https://github.com/awslabs/swift-aws-lambda-runtime.git", from: "2.5.0"),
2323
.package(url: "https://github.com/awslabs/swift-aws-lambda-events.git", from: "0.5.0"),
2424
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.22.0"),
2525
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3"),

Sources/BreezeDemoHTTPApplication/BreezeDemoHTTPApplication.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ struct DemoLambdaHandler: BreezeLambdaWebHookHandler, Sendable {
2929
self.handlerContext = handlerContext
3030
}
3131

32+
var httpClient: HTTPClient {
33+
handlerContext.httpClient
34+
}
35+
3236
func handle(_ event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
3337
context.logger.info("Received event: \(event)")
3438
let request = HTTPClientRequest(url: "https://example.com")
35-
let response = try await handlerContext.httpClient.execute(request, timeout: .seconds(5))
39+
let response = try await httpClient.execute(request, timeout: .seconds(5))
3640
let bytes = try await response.body.collect(upTo: 1024 * 1024) // 1 MB Buffer
3741
let body = String(buffer: bytes)
3842
context.logger.info("Response body: \(body)")

Sources/BreezeLambdaWebHook/BreezeLambdaWebHook.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,20 @@ public struct BreezeLambdaWebHook<LambdaHandler: BreezeLambdaWebHookHandler>: Se
5353
/// handling any errors that may occur during the process.
5454
/// It gracefully shuts down the service on termination signals.
5555
public func run() async throws {
56+
let handlerContext = HandlerContext(config: config)
57+
let lambdaHandler = LambdaHandler(handlerContext: handlerContext)
58+
let runtime = LambdaRuntime(body: lambdaHandler.handle)
59+
60+
let serviceGroup = ServiceGroup(
61+
services: [handlerContext, runtime],
62+
gracefulShutdownSignals: [.sigterm, .sigint],
63+
logger: config.logger
64+
)
5665
do {
57-
let lambdaService = BreezeLambdaWebHookService<LambdaHandler>(
58-
config: config
59-
)
60-
let serviceGroup = ServiceGroup(
61-
services: [lambdaService],
62-
gracefulShutdownSignals: [.sigterm, .sigint],
63-
logger: config.logger
64-
)
6566
config.logger.error("Starting \(name) ...")
6667
try await serviceGroup.run()
6768
} catch {
69+
try? handlerContext.syncShutdown()
6870
config.logger.error("Error running \(name): \(error.localizedDescription)")
6971
}
7072
}

Sources/BreezeLambdaWebHook/BreezeLambdaWebHookHandler.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ public extension BreezeLambdaWebHookHandler {
3232
var handler: String? {
3333
Lambda.env("_HANDLER")
3434
}
35-
36-
var httpClient: AsyncHTTPClient.HTTPClient {
37-
handlerContext.httpClient
38-
}
3935
}

0 commit comments

Comments
 (0)