Skip to content

Commit

Permalink
Merge pull request #145 from cdklabs/dev
Browse files Browse the repository at this point in the history
chore: refactor: build lambda
  • Loading branch information
wchaws authored Dec 5, 2021
2 parents 164e813 + dd19516 commit 9350661
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CDK construct to deploy docker image to Amazon ECR
Run [test/integ.ecr-deployment.ts](./test/integ.ecr-deployment.ts)

```shell
npx cdk deploy -a "npx ts-node -P tsconfig.jest.json --prefer-ts-exts test/integ.ecr-deployment.ts"
NO_PREBUILT_LAMBDA=1 npx cdk deploy -a "npx ts-node -P tsconfig.dev.json --prefer-ts-exts test/integ.ecr-deployment.ts"
```

## Tech Details & Contribution
Expand Down
9 changes: 9 additions & 0 deletions lambda/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Dockerfile
Dockerfile*
node_modules
coverage
test-reports
**/*.md
main
main.sha256
cdk.out
15 changes: 11 additions & 4 deletions lambda/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ FROM lambci/lambda:build-go1.x

USER root

ADD . /ws

RUN yum -y install \
gpgme-devel \
btrfs-progs-devel \
Expand All @@ -17,9 +15,18 @@ RUN yum -y install \

ENV GOOS=linux \
GOARCH=amd64 \
GO111MODULE=on \
GOPROXY=https://goproxy.cn,https://goproxy.io,direct

# run tests
WORKDIR /ws

RUN make OUTPUT=/ws/main
COPY go.mod go.sum ./

RUN go mod download -x

COPY . /ws

RUN mkdir -p /asset/ && \
make OUTPUT=/asset/main && \
file /asset/main && \
ls -lh /asset/main
2 changes: 1 addition & 1 deletion lambda/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ upgrade-deps:
CGO_ENABLED=0 $(GPGME_ENV) $(GO) get -u -tags "$(BUILDTAGS)"

lambda:
CGO_ENABLED=0 $(GPGME_ENV) $(GO) build ${GO_DYN_FLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $(OUTPUT)
CGO_ENABLED=0 $(GPGME_ENV) $(GO) build -v ${GO_DYN_FLAGS} -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o $(OUTPUT)

test:
CGO_ENABLED=0 $(GPGME_ENV) $(GO) test -v -tags "$(BUILDTAGS)" ./...
2 changes: 0 additions & 2 deletions lambda/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zM
github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.2-0.20211123152302-43a7dee1ec31 h1:Wh4aR2I6JFwySre9m3iHJYuMnvUFE/HT6qAXozRWi/E=
github.com/opencontainers/image-spec v1.0.2-0.20211123152302-43a7dee1ec31/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v1.0.0-rc8.0.20190926000215-3e425f80a8c9/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
Expand Down
22 changes: 2 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';

// eslint-disable-next-line no-duplicate-imports, import/order
import { AssetHashType, Construct as CoreConstruct } from '@aws-cdk/core';
import { Construct as CoreConstruct } from '@aws-cdk/core';

export interface ECRDeploymentProps {
/**
Expand Down Expand Up @@ -94,25 +94,7 @@ function getCode(): lambda.AssetCode {

console.log('Build lambda from scratch');

return lambda.Code.fromAsset(path.join(__dirname, '../lambda'), {
assetHashType: AssetHashType.SOURCE, // see https://github.com/aws/aws-cdk/pull/12984
bundling: {
image: lambda.Runtime.GO_1_X.bundlingImage,
environment: {
GOGC: '50',
GOOS: 'linux',
GOARCH: 'amd64',
GOPROXY: 'https://goproxy.cn,https://goproxy.io,direct',
},
user: 'root',
command: [
'bash', '-c', [
'yum -y install gpgme-devel btrfs-progs-devel device-mapper-devel libassuan-devel libudev-devel',
'make OUTPUT=/asset-output/main',
].join(' && '),
],
},
});
return lambda.Code.fromDockerBuild(path.join(__dirname, '../lambda'));
}

export class DockerImageName implements IImageName {
Expand Down
5 changes: 2 additions & 3 deletions test/integ.ecr-deployment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as path from 'path';
import * as ecr from '@aws-cdk/aws-ecr';
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0


import * as path from 'path';
import * as ecr from '@aws-cdk/aws-ecr';
import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';
import * as cdk from '@aws-cdk/core';
// eslint-disable-next-line no-duplicate-imports
Expand Down

0 comments on commit 9350661

Please sign in to comment.