Skip to content

Commit

Permalink
begin implementing deploy backend
Browse files Browse the repository at this point in the history
  • Loading branch information
djelusic committed Jul 22, 2021
1 parent 2ede9c5 commit 39e1fe2
Show file tree
Hide file tree
Showing 26 changed files with 1,736 additions and 64 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
main.tf
.terraform
.terraform.lock.hcl
44 changes: 44 additions & 0 deletions api/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package deploy

import (
"context"

"github.com/atoz-technology/mantil-backend/internal/deploy"
"github.com/atoz-technology/mantil-backend/internal/mantil"
)

type Deploy struct{}

type DeployRequest struct {
ProjectBucket string //TODO use mantil token here
FunctionUpdates []mantil.FunctionUpdate
}
type DeployResponse struct {
Response string
}

func (h *Deploy) Init(ctx context.Context) {}

func (h *Deploy) Invoke(ctx context.Context, req *DeployRequest) (*DeployResponse, error) {
return h.Deploy(ctx, req)
}

func (h *Deploy) Deploy(ctx context.Context, req *DeployRequest) (*DeployResponse, error) {
p, err := mantil.LoadProject(req.ProjectBucket)
if err != nil {
return nil, err
}
d, err := deploy.New(p, req.FunctionUpdates, ".")
if err != nil {
return nil, err
}
if err := d.Deploy(); err != nil {
return nil, err
}
rsp := DeployResponse{Response: "success"}
return &rsp, nil
}

func New() *Deploy {
return &Deploy{}
}
60 changes: 0 additions & 60 deletions api/hello/hello.go

This file was deleted.

12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash -e

WORK_DIR=~/work
ASSETS_DIR=$WORK_DIR/mantil-backend/internal/assets

zip -j funcs.zip $WORK_DIR/terraform-aws-modules/funcs/*.tf
mv funcs.zip $ASSETS_DIR/terraform/modules

zip -j dynamodb.zip $WORK_DIR/terraform-aws-modules/dynamodb/*.tf
mv dynamodb.zip $ASSETS_DIR/terraform/modules

(cd $ASSETS_DIR && go-bindata -pkg=assets -fs github/ terraform/modules/ terraform/templates/ aws/)
1 change: 1 addition & 0 deletions functions/deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deploy
37 changes: 37 additions & 0 deletions functions/deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM public.ecr.aws/lambda/go:latest

# terrraform install
RUN yum -y install unzip wget git
ARG version=1.0.0
ARG arch=_linux_amd64 #_linux_arm64
RUN wget https://releases.hashicorp.com/terraform/$version/terraform_${version}${arch}.zip \
&& unzip terraform_${version}${arch}.zip \
&& rm terraform_${version}${arch}.zip \
&& mv terraform /usr/bin/ \
&& terraform --version
ENV TF_IN_AUTOMATION=1

# aws cli install
# ref: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install

# ARG AWS_ACCESS_KEY_ID
# ARG AWS_SECRET_ACCESS_KEY
# ARG AWS_DEFAULT_REGION

# get secrets from s3 bucket
# RUN mkdir -p /secrets \
# && cd /secrets \
# && aws s3 sync s3://atoz-technology-mantil-secrets /secrets \
# && mkdir -p /root/.aws \
# && cp /secrets/atoz/config /root/.aws \
# && cp /secrets/atoz/credentials /root/.aws

# ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
# ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
# ENV AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION

COPY deploy /var/task/
CMD [ "deploy" ]
4 changes: 2 additions & 2 deletions functions/hello/main.go → functions/deploy/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"github.com/atoz-technology/mantil-backend/api/hello"
"github.com/atoz-technology/mantil-backend/api/deploy"
"github.com/atoz-technology/mantil.go"
)

func main() {
var api = hello.New()
var api = deploy.New()
mantil.LambdaHandler(api)
}
1 change: 0 additions & 1 deletion functions/hello/.gitignore

This file was deleted.

10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ module github.com/atoz-technology/mantil-backend

go 1.16

require github.com/atoz-technology/mantil.go v0.0.0-20210703191630-fbb418468f70 // indirect
require (
github.com/atoz-technology/mantil.go v0.0.0-20210703191630-fbb418468f70 // indirect
github.com/aws/aws-sdk-go-v2 v1.7.1
github.com/aws/aws-sdk-go-v2/config v1.5.0
github.com/aws/aws-sdk-go-v2/service/lambda v1.5.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.11.1
github.com/aws/aws-sdk-go-v2/service/sts v1.6.0 // indirect
github.com/aws/smithy-go v1.6.0 // indirect
)
33 changes: 33 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,52 @@ github.com/atoz-technology/mantil.go v0.0.0-20210703191630-fbb418468f70 h1:5M8zM
github.com/atoz-technology/mantil.go v0.0.0-20210703191630-fbb418468f70/go.mod h1:01VElwN3v9kPSMQ9er4v15sluHcxpM51MABnAFl42/Y=
github.com/aws/aws-lambda-go v1.24.0 h1:bOMerM175hLqHLdF1Nonfv1NA20nTIatuC0HK8eMoYg=
github.com/aws/aws-lambda-go v1.24.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU=
github.com/aws/aws-sdk-go-v2 v1.7.1 h1:TswSc7KNqZ/K1Ijt3IkpXk/2+62vi3Q82Yrr5wSbRBQ=
github.com/aws/aws-sdk-go-v2 v1.7.1/go.mod h1:L5LuPC1ZgDr2xQS7AmIec/Jlc7O/Y1u2KxJyNVab250=
github.com/aws/aws-sdk-go-v2/config v1.5.0 h1:tRQcWXVmO7wC+ApwYc2LiYKfIBoIrdzcJ+7HIh6AlR0=
github.com/aws/aws-sdk-go-v2/config v1.5.0/go.mod h1:RWlPOAW3E3tbtNAqTwvSW54Of/yP3oiZXMI0xfUdjyA=
github.com/aws/aws-sdk-go-v2/credentials v1.3.1 h1:fFeqL5+9kwFKsCb2oci5yAIDsWYqn/Nga8oQ5bIasI8=
github.com/aws/aws-sdk-go-v2/credentials v1.3.1/go.mod h1:r0n73xwsIVagq8RsxmZbGSRQFj9As3je72C2WzUIToc=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.3.0 h1:s4vtv3Mv1CisI3qm2HGHi1Ls9ZtbCOEqeQn6oz7fTyU=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.3.0/go.mod h1:2LAuqPx1I6jNfaGDucWfA2zqQCYCOMCDHiCOciALyNw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.1.1 h1:SDLwr1NKyowP7uqxuLNdvFZhjnoVWxNv456zAp+ZFjU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.1.1/go.mod h1:Zy8smImhTdOETZqfyn01iNOe0CNggVbPjCajyaz6Gvg=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.2.1 h1:s/uV8UyMB4UcO0ERHxG9BJhYJAD9MiY0QeYvJmlC7PE=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.2.1/go.mod h1:v33JQ57i2nekYTA70Mb+O18KeH4KqhdqxTJZNK1zdRE=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.1 h1:VJe/XEhrfyfBLupcGg1BfUSK2VMZNdbDcZQ49jnp+h0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.1/go.mod h1:zceowr5Z1Nh2WVP8bf/3ikB41IZW59E4yIYbg+pC6mw=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.5.1 h1:1ds3HkMQEBx9XvOkqsPuqBmNFn0w8XEDuB4LOi6KepU=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.5.1/go.mod h1:6EQZIwNNvHpq/2/QSJnp4+ECvqIy55w95Ofs0ze+nGQ=
github.com/aws/aws-sdk-go-v2/service/lambda v1.5.0 h1:30HxyBuZswg258SRElKVaNrC80X4uBI6KiYWHco8HwY=
github.com/aws/aws-sdk-go-v2/service/lambda v1.5.0/go.mod h1:TteTjjmrgkcXILeeeEAIsg5NTkfHHVHxyNPBl6gL8uU=
github.com/aws/aws-sdk-go-v2/service/s3 v1.11.1 h1:HiXhafnqG0AkVJIZA/BHhFvuc/8xFdUO1uaeqF2Artc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.11.1/go.mod h1:XLAGFrEjbvMCLvAtWLLP32yTv8GpBquCApZEycDLunI=
github.com/aws/aws-sdk-go-v2/service/sso v1.3.1 h1:H2ZLWHUbbeYtghuqCY5s/7tbBM99PAwCioRJF8QvV/U=
github.com/aws/aws-sdk-go-v2/service/sso v1.3.1/go.mod h1:J3A3RGUvuCZjvSuZEcOpHDnzZP/sKbhDWV2T1EOzFIM=
github.com/aws/aws-sdk-go-v2/service/sts v1.6.0 h1:Y9r6mrzOyAYz4qKaluSH19zqH1236il/nGbsPKOUT0s=
github.com/aws/aws-sdk-go-v2/service/sts v1.6.0/go.mod h1:q7o0j7d7HrJk/vr9uUt3BVRASvcU7gYZB9PUgPiByXg=
github.com/aws/smithy-go v1.6.0 h1:T6puApfBcYiTIsaI+SYWqanjMt5pc3aoyyDrI+0YH54=
github.com/aws/smithy-go v1.6.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20 changes: 20 additions & 0 deletions internal/assets/aws/project-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::{{.Bucket}}"
},
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "arn:aws:s3:::{{.Bucket}}/*"
},
{
"Effect": "Allow",
"Action": "ecr:*",
"Resource": "arn:aws:ecr:*:*:repository/mantil-project-{{.Organization.Name}}-{{.Name}}"
}
]
}
Loading

0 comments on commit 39e1fe2

Please sign in to comment.