-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update golang.yml workflow to copy golang-build-deploy.sh from…
… the correct directory
- Loading branch information
1 parent
15a5adb
commit b913895
Showing
10 changed files
with
153 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/bash | ||
|
||
file=$1 | ||
S3_BUCKET_NAME="my-unique-bucket-golang-lambda-test" | ||
|
||
while read line; do | ||
# Remove starting and ending square brackets using parameter expansion | ||
line="${line#\[}" # Remove starting square bracket | ||
line="${line%\]}" # Remove ending square bracket | ||
printf '%s\n' "$line" | ||
IFS=',' read -ra parts <<< "$line" | ||
|
||
# Iterate over the split parts and echo each one | ||
for part in "${parts[@]}"; do | ||
# Remove any leading or trailing spaces | ||
directory_path=$(echo "$part" | tr -d '[:space:]' | sed 's/"//g' | sed 's#^github/##;s#/main\.go$##') | ||
printf '%s\n' "$directory_path" | ||
|
||
# Extract the path without the filename and the initial 'lambda/' part | ||
zip_name=$(dirname "$directory_path" | sed 's|^lambda/||') | ||
|
||
# Determine if the last segment is 'src' or not | ||
last_segment=$(basename "$zip_name") | ||
|
||
if [ "$last_segment" = "src" ]; then | ||
# Remove the last segment if it is 'src' | ||
zip_name =$(dirname "$zip_name") | ||
fi | ||
|
||
# Replace '/' with '_' | ||
result=$(echo "$zip_name" | tr '/' '_') | ||
|
||
echo "$result" | ||
|
||
|
||
# Check if the directory exists | ||
if [ -d "$directory_path" ]; then | ||
# Store the current directory | ||
current_dir="$(pwd)" | ||
|
||
# Change to the target directory | ||
cd "$directory_path" | ||
|
||
# Run the build command in the directory | ||
echo "Building in directory $directory_path:" | ||
# Run the build command in the directory and capture the output | ||
build_output=$(GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o bootstrap 2>&1) | ||
# zip_name=$(echo "$directory_path" | awk -F'/' '{print $2}') | ||
|
||
# Check the exit status of the build command | ||
if [ $? -eq 0 ]; then | ||
echo "Build in directory $directory_path succeeded:" | ||
echo "$build_output" | ||
# Zip the bootstrap file | ||
zip -q "$result.zip" bootstrap | ||
echo "Bootstrap file zipped as bootstrap.zip" | ||
echo "Uploading to AWS S3" | ||
aws s3 cp "$result.zip" "s3://$S3_BUCKET_NAME/$result.zip" | ||
|
||
else | ||
echo "Build in directory $directory_path failed:" | ||
echo "$build_output" | ||
fi | ||
|
||
# Return to the original directory | ||
cd "$current_dir" | ||
else | ||
echo "Directory $directory_path does not exist." | ||
fi | ||
done | ||
|
||
done < list.txt |
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ func handler(ctx context.Context) (string, error) { | |
|
||
func main() { | ||
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ func handler(ctx context.Context) (string, error) { | |
|
||
func main() { | ||
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,23 @@ | ||
# Download package from S3 | ||
data "aws_s3_object" "application_zip" { | ||
bucket = var.s3_bucket | ||
key = "payments_gateways_stripe_confirm.zip" | ||
} | ||
|
||
# Lambda module to deploy using terraform | ||
module "lambda_function" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
|
||
function_name = "payments_gateways_stripe_confirm" | ||
description = "This lambda is being deployed from github" | ||
handler = "bootstrap" | ||
runtime = "provided.al2023" | ||
architectures = ["arm64"] | ||
create_package = false | ||
s3_existing_package = { | ||
bucket = data.aws_s3_object.application_zip.bucket | ||
key = data.aws_s3_object.application_zip.key | ||
version_id = data.aws_s3_object.application_zip.version_id | ||
} | ||
|
||
} |
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,5 @@ | ||
module main | ||
|
||
go 1.21.1 | ||
|
||
require github.com/aws/aws-lambda-go v1.41.0 |
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,10 @@ | ||
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y= | ||
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= | ||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
// handler is the main Lambda function handler | ||
func handler(ctx context.Context) (string, error) { | ||
message := "Hello, World!" | ||
fmt.Println(message) | ||
return message, nil | ||
} | ||
|
||
func main() { | ||
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,4 @@ | ||
# This variable is used to specify the S3 bucket name. | ||
variable "s3_bucket" { | ||
type = string | ||
} |
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 @@ | ||
["lambda/github-lambda-test-1/src/main.go","lambda/github-lambda-test-2/src/main.go"] |