-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of deploying a Go project to fargate.
- Loading branch information
Showing
9 changed files
with
158 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
load("@rules_oci//oci:defs.bzl", "oci_image") | ||
load("@rules_pkg//pkg:tar.bzl", "pkg_tar") | ||
load("//bzl:rules.bzl", "bazel_lint") | ||
load("//go:rules.bzl", "go_binary", "go_library") | ||
load("//ts:rules.bzl", "ts_project") | ||
load("//ts/pulumi/lib/oci:rules.bzl", "pulumi_image") | ||
|
||
go_library( | ||
name = "hello_world_lib", | ||
srcs = ["hello.go"], | ||
importpath = "github.com/zemn-me/monorepo/ts/pulumi/zemn.me/hello_world", | ||
visibility = ["//visibility:private"], | ||
deps = ["@com_github_aws_aws_lambda_go//lambda"], | ||
) | ||
|
||
go_binary( | ||
name = "hello_world", | ||
embed = [":hello_world_lib"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
bazel_lint( | ||
name = "bazel_lint", | ||
srcs = ["BUILD.bazel"], | ||
) | ||
|
||
pkg_tar( | ||
name = "tar", | ||
srcs = [":hello_world"], | ||
) | ||
|
||
oci_image( | ||
name = "image", | ||
base = "@distroless_base", | ||
entrypoint = ["/hello_world"], | ||
tars = [":tar"], | ||
) | ||
|
||
pulumi_image( | ||
name = "oci_image", | ||
src = ":image", | ||
component_name = "HelloWorldImage", | ||
) | ||
|
||
ts_project( | ||
name = "ts", | ||
srcs = [ | ||
"hello_world.ts", | ||
], | ||
visibility = [ | ||
"//ts/pulumi:__subpackages__", | ||
], | ||
deps = [ | ||
":oci_image", | ||
"//:node_modules/@pulumi/aws", | ||
"//:node_modules/@pulumi/awsx", | ||
"//:node_modules/@pulumi/pulumi", | ||
"//ts/pulumi/lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
// Handler is the Lambda function entry point | ||
func Handler(ctx context.Context) (string, error) { | ||
return "Hello, World!", nil | ||
} | ||
|
||
func main() { | ||
// Start the Lambda function | ||
lambda.Start(Handler) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ecs } from "@pulumi/aws"; | ||
import * as awsx from "@pulumi/awsx"; | ||
import { ComponentResource, ComponentResourceOptions, interpolate } from "@pulumi/pulumi"; | ||
|
||
import { mergeTags, TagSet, tagTrue } from "#root/ts/pulumi/lib/tags.js"; | ||
import { HelloWorldImage } from '#root/ts/pulumi/zemn.me/hello_world/HelloWorldImage.js'; | ||
|
||
|
||
|
||
export interface Args { | ||
tags?: TagSet | ||
} | ||
|
||
export class FargateHelloWorld extends ComponentResource { | ||
constructor( | ||
name: string, | ||
args: Args, | ||
opts?: ComponentResourceOptions | ||
) { | ||
super('ts:pulumi:Component', name, args, opts); | ||
const tag = name; | ||
const tags = mergeTags(args.tags, tagTrue(tag)); | ||
|
||
const cluster = new ecs.Cluster("cluster", { | ||
tags: tags | ||
}); | ||
|
||
// Create the ECR repository to store our container image | ||
const repo = new awsx.ecr.Repository("repo", { | ||
forceDelete: true, | ||
tags: tags | ||
}); | ||
|
||
// Create a load balancer to listen for requests and route them to the container. | ||
const loadbalancer = new awsx.lb.ApplicationLoadBalancer("loadbalancer", {}); | ||
|
||
const img = new HelloWorldImage( | ||
`${name}_img`, | ||
{ | ||
repository: repo.url, | ||
} | ||
) | ||
|
||
// Define the service and configure it to use our image and load balancer. | ||
new awsx.ecs.FargateService("service", { | ||
cluster: cluster.arn, | ||
assignPublicIp: true, | ||
taskDefinitionArgs: { | ||
container: { | ||
name: "awsx-ecs", | ||
image: img.url, | ||
cpu: 128, | ||
memory: 512, | ||
essential: true, | ||
portMappings: [{ | ||
containerPort: 80, | ||
targetGroup: loadbalancer.defaultTargetGroup, | ||
}], | ||
}, | ||
}, | ||
}); | ||
|
||
// Export the URL so we can easily access it. | ||
const frontendURL = interpolate`http://${loadbalancer.loadBalancer.dnsName}`; | ||
|
||
this.registerOutputs({ | ||
frontendURL: frontendURL, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters