From b2b2d94377df7d031ccdb6a7d860e5eb33b914f3 Mon Sep 17 00:00:00 2001 From: javacs3 Date: Sun, 5 Dec 2021 19:15:59 +0800 Subject: [PATCH 1/3] docs: fix docs error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19454d15..940a3df1 100644 --- a/README.md +++ b/README.md @@ -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 From 3f68cb608494f4be931a86ea3890a917c7d76e78 Mon Sep 17 00:00:00 2001 From: javacs3 Date: Sun, 5 Dec 2021 20:31:14 +0800 Subject: [PATCH 2/3] refactor: build lambda --- lambda/.dockerignore | 9 +++++++++ lambda/Dockerfile | 15 +++++++++++---- lambda/go.sum | 2 -- src/index.ts | 22 ++-------------------- test/integ.ecr-deployment.ts | 5 ++--- 5 files changed, 24 insertions(+), 29 deletions(-) create mode 100644 lambda/.dockerignore diff --git a/lambda/.dockerignore b/lambda/.dockerignore new file mode 100644 index 00000000..21b0a79f --- /dev/null +++ b/lambda/.dockerignore @@ -0,0 +1,9 @@ +Dockerfile +Dockerfile* +node_modules +coverage +test-reports +**/*.md +main +main.sha256 +cdk.out \ No newline at end of file diff --git a/lambda/Dockerfile b/lambda/Dockerfile index 0e3844ea..c09b05a0 100644 --- a/lambda/Dockerfile +++ b/lambda/Dockerfile @@ -6,8 +6,6 @@ FROM lambci/lambda:build-go1.x USER root -ADD . /ws - RUN yum -y install \ gpgme-devel \ btrfs-progs-devel \ @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/lambda/go.sum b/lambda/go.sum index 5c7f7a2e..641afce3 100644 --- a/lambda/go.sum +++ b/lambda/go.sum @@ -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= diff --git a/src/index.ts b/src/index.ts index 938c71b1..64355dc3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { /** @@ -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 { diff --git a/test/integ.ecr-deployment.ts b/test/integ.ecr-deployment.ts index 0b5e5f44..07d3ca43 100644 --- a/test/integ.ecr-deployment.ts +++ b/test/integ.ecr-deployment.ts @@ -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 From dd195162e0b042c666a63bf57cbec9a4bcac1a17 Mon Sep 17 00:00:00 2001 From: javacs3 Date: Sun, 5 Dec 2021 20:50:51 +0800 Subject: [PATCH 3/3] chore: add verbose on go build --- lambda/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/Makefile b/lambda/Makefile index 4a69abaa..b9c62116 100644 --- a/lambda/Makefile +++ b/lambda/Makefile @@ -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)" ./... \ No newline at end of file