codebuild+ecs+ecr+s3+ssm

codebuild+ecs+ecr+s3+ssm 

1、准备工作

在使用codebuild时,源代码从s3中拉取,构建的docker image从ecr中拉取,因此要提前建好s3存储桶,ecr仓库。(避免发生意外的情况,所有服务均建在同一个region,此教程均在cn-northwest-1下操作)

1.1、s3存储桶

  创建的时候,只指定区域和存储桶的名字,其余默认。

1.1.1、上传带有buildspec.yml的zip包

1.2、ecr私有仓库

创建的时候,只指定仓库的名字,其余默认。

 

即使在给codebuild所附加的角色上添加可以访问ecr的权限时,有可能还是拉取不了此仓库的镜像。对此ecr仓库赋予权限(不是最小权限)

 
 1 {
 2   "Version": "2008-10-17",
 3   "Statement": [
 4     {
 5       "Sid": "AllowPull",
 6       "Effect": "Allow",
 7       "Principal": "*",
 8       "Action": [
 9         "ecr:BatchCheckLayerAvailability",
10         "ecr:BatchGetImage",
11         "ecr:GetDownloadUrlForLayer"
12       ]
13     }
14   ]
15 }
ecr仓库策略

 

1.2.1、上传基准镜像

 

(前提:本机配好ak sk,以及docker运行环境)

2、创建codebuild

 

之后启动构建,默认参数是创建构建项目时填入的参数。

对codebuild角色添加权限 

  1 [Container] 2019/11/22 03:56:08 Waiting for agent ping
  2 [Container] 2019/11/22 03:56:10 Waiting for DOWNLOAD_SOURCE
  3 [Container] 2019/11/22 03:56:10 Phase is DOWNLOAD_SOURCE
  4 [Container] 2019/11/22 03:56:10 CODEBUILD_SRC_DIR=/codebuild/output/src373328726/src
  5 [Container] 2019/11/22 03:56:10 YAML location is /codebuild/output/src373328726/src/buildspec.yml
  6 [Container] 2019/11/22 03:56:10 Processing environment variables
  7 [Container] 2019/11/22 03:56:10 Decrypting parameter store environment variables
  8 [Container] 2019/11/22 03:56:10 Moving to directory /codebuild/output/src373328726/src
  9 [Container] 2019/11/22 03:56:10 Registering with agent
 10 [Container] 2019/11/22 03:56:10 Phases found in YAML: 4
 11 [Container] 2019/11/22 03:56:10  INSTALL: 12 commands
 12 [Container] 2019/11/22 03:56:10  PRE_BUILD: 2 commands
 13 [Container] 2019/11/22 03:56:10  BUILD: 4 commands
 14 [Container] 2019/11/22 03:56:10  POST_BUILD: 8 commands
 15 [Container] 2019/11/22 03:56:10 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
 16 [Container] 2019/11/22 03:56:10 Phase context status code:  Message: 
 17 [Container] 2019/11/22 03:56:10 Entering phase INSTALL
 18 [Container] 2019/11/22 03:56:10 Running command echo "Installing Docker version 18 ..."
 19 Installing Docker version 18 ...
 20   
 21 [Container] 2019/11/22 03:56:10 Running command echo "Installing Go version 1.13 ..."
 22 Installing Go version 1.13 ...
 23   
 24 [Container] 2019/11/22 03:56:10 Running command echo Entered the install phase...
 25 Entered the install phase...
 26   
 27 [Container] 2019/11/22 03:56:10 Running command apt-get update -y
 28 Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
 29 Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
 30 Get:3 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
 31 Get:4 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic InRelease [20.7 kB]
 32 Get:5 http://archive.canonical.com/ubuntu bionic InRelease [10.2 kB]
 33 Get:6 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
 34 Ign:7 https://dl.bintray.com/sbt/debian  InRelease
 35 Get:8 https://download.mono-project.com/repo/ubuntu stable-bionic InRelease [5143 B]
 36 Get:9 https://dl.bintray.com/sbt/debian  Release [815 B]
 37 Get:10 https://dl.bintray.com/sbt/debian  Release.gpg [821 B]
 38 Hit:11 http://ppa.launchpad.net/malteworld/ppa/ubuntu bionic InRelease
 39 Get:12 https://dl.yarnpkg.com/debian stable/main amd64 Packages [9199 B]
 40 Get:13 http://archive.canonical.com/ubuntu bionic/partner amd64 Packages [2343 B]
 41 Get:14 https://download.mono-project.com/repo/ubuntu stable-bionic/main i386 Packages [48.9 kB]
 42 Get:15 https://dl.yarnpkg.com/debian stable/main all Packages [9199 B]
 43 Get:16 http://archive.canonical.com/ubuntu bionic/partner i386 Packages [2345 B]
 44 Get:17 https://dl.bintray.com/sbt/debian  Packages [3753 B]
 45 Get:18 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu bionic InRelease [15.4 kB]
 46 Get:19 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
 47 Get:20 https://download.mono-project.com/repo/ubuntu stable-bionic/main amd64 Packages [48.9 kB]
 48 Get:21 https://dl.yarnpkg.com/debian stable/main i386 Packages [9199 B]
 49 Get:22 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [736 kB]
 50 Get:23 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic InRelease [15.4 kB]
 51 Get:24 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic/main i386 Packages [3162 B]
 52 Get:25 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1032 kB]
 53 Get:26 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic/main amd64 Packages [3163 B]
 54 Get:27 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu bionic/main amd64 Packages [7879 B]
 55 Get:28 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu bionic/main i386 Packages [7815 B]
 56 Get:29 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic/main amd64 Packages [26.9 kB]
 57 Get:30 http://archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1268 kB]
 58 Get:31 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic/main i386 Packages [25.1 kB]
 59 Get:32 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [16.8 kB]
 60 Get:33 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [787 kB]
 61 Get:34 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [29.9 kB]
 62 Get:35 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [9578 B]
 63 Get:36 http://archive.ubuntu.com/ubuntu bionic-updates/restricted i386 Packages [13.6 kB]
 64 Get:37 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1314 kB]
 65 Get:38 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [756 kB]
 66 Get:39 http://security.ubuntu.com/ubuntu bionic-security/multiverse i386 Packages [4510 B]
 67 Get:40 http://archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [797 kB]
 68 Get:41 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages [517 kB]
 69 Get:42 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse i386 Packages [7584 B]
 70 Get:43 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [6508 B]
 71 Get:44 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [4235 B]
 72 Get:45 http://archive.ubuntu.com/ubuntu bionic-backports/universe i386 Packages [4240 B]
 73 Fetched 7850 kB in 16s (486 kB/s)
 74 Reading package lists...
 75   
 76 [Container] 2019/11/22 03:56:37 Running command apt-get install -y git tree
 77 Reading package lists...
 78 Building dependency tree...
 79 Reading state information...
 80 The following additional packages will be installed:
 81   git-man
 82 Suggested packages:
 83   git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk
 84   gitweb git-cvs git-mediawiki git-svn
 85 The following NEW packages will be installed:
 86   tree
 87 The following packages will be upgraded:
 88   git git-man
 89 2 upgraded, 1 newly installed, 0 to remove and 238 not upgraded.
 90 Need to get 7911 kB of archives.
 91 After this operation, 452 kB of additional disk space will be used.
 92 Get:1 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic/main amd64 git amd64 1:2.24.0-1~ppa0~ubuntu18.04.1 [6176 kB]
 93 Get:2 http://archive.ubuntu.com/ubuntu bionic/universe amd64 tree amd64 1.7.0-5 [40.7 kB]
 94 Get:3 http://ppa.launchpad.net/git-core/ppa/ubuntu bionic/main amd64 git-man all 1:2.24.0-1~ppa0~ubuntu18.04.1 [1695 kB]
 95 debconf: delaying package configuration, since apt-utils is not installed
 96 Fetched 7911 kB in 4s (2164 kB/s)
 97 (Reading database ... 
 98 (Reading database ... 5%
 99 (Reading database ... 10%
100 (Reading database ... 15%
101 (Reading database ... 20%
102 (Reading database ... 25%
103 (Reading database ... 30%
104 (Reading database ... 35%
105 (Reading database ... 40%
106 (Reading database ... 45%
107 (Reading database ... 50%
108 (Reading database ... 55%
109 (Reading database ... 60%
110 (Reading database ... 65%
111 (Reading database ... 70%
112 (Reading database ... 75%
113 (Reading database ... 80%
114 (Reading database ... 85%
115 (Reading database ... 90%
116 (Reading database ... 95%
117 (Reading database ... 100%
118 (Reading database ... 48947 files and directories currently installed.)
119 Preparing to unpack .../git_1%3a2.24.0-1~ppa0~ubuntu18.04.1_amd64.deb ...
120 Unpacking git (1:2.24.0-1~ppa0~ubuntu18.04.1) over (1:2.23.0-0ppa1~ubuntu18.04.1) ...
121 Preparing to unpack .../git-man_1%3a2.24.0-1~ppa0~ubuntu18.04.1_all.deb ...
122 Unpacking git-man (1:2.24.0-1~ppa0~ubuntu18.04.1) over (1:2.23.0-0ppa1~ubuntu18.04.1) ...
123 Selecting previously unselected package tree.
124 Preparing to unpack .../tree_1.7.0-5_amd64.deb ...
125 Unpacking tree (1.7.0-5) ...
126 Setting up tree (1.7.0-5) ...
127 Setting up git-man (1:2.24.0-1~ppa0~ubuntu18.04.1) ...
128 Setting up git (1:2.24.0-1~ppa0~ubuntu18.04.1) ...
129   
130 [Container] 2019/11/22 03:56:51 Running command apt-get install -y python3-pip
131 Reading package lists...
132 Building dependency tree...
133 Reading state information...
134 python3-pip is already the newest version (9.0.1-2.3~ubuntu1.18.04.1).
135 0 upgraded, 0 newly installed, 0 to remove and 238 not upgraded.
136   
137 [Container] 2019/11/22 03:56:53 Running command mkdir -p ~/.pip
138   
139 [Container] 2019/11/22 03:56:53 Running command echo "[global]" >>   ~/.pip/pip.conf
140   
141 [Container] 2019/11/22 03:56:53 Running command echo "timeout = 6000" >>   ~/.pip/pip.conf
142   
143 [Container] 2019/11/22 03:56:53 Running command echo "index-url = https://mirrors.aliyun.com/pypi/simple/" >>   ~/.pip/pip.conf
144   
145 [Container] 2019/11/22 03:56:53 Running command echo "trusted-host = mirrors.aliyun.com" >>   ~/.pip/pip.conf
146   
147 [Container] 2019/11/22 03:56:53 Running command cat ~/.pip/pip.conf
148 [global]
149 timeout = 6000
150 index-url = https://mirrors.aliyun.com/pypi/simple/
151 trusted-host = mirrors.aliyun.com
152   
153 [Container] 2019/11/22 03:56:53 Running command pip3 --version
154 pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
155   
156 [Container] 2019/11/22 03:56:59 Running command pip3 install awscli
157 Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
158 Collecting awscli
159   Downloading https://mirrors.aliyun.com/pypi/packages/70/e1/97939dbbc7d609661c12c544975326fdef69a6d492f0ad87011459b1134f/awscli-1.16.289-py2.py3-none-any.whl (2.5MB)
160 Collecting rsa<=3.5.0,>=3.1.2 (from awscli)
161   Downloading https://mirrors.aliyun.com/pypi/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl (46kB)
162 Collecting docutils<0.16,>=0.10 (from awscli)
163   Downloading https://mirrors.aliyun.com/pypi/packages/22/cd/a6aa959dca619918ccb55023b4cb151949c64d4d5d55b3f4ffd7eee0c6e8/docutils-0.15.2-py3-none-any.whl (547kB)
164 Collecting s3transfer<0.3.0,>=0.2.0 (from awscli)
165   Downloading https://mirrors.aliyun.com/pypi/packages/16/8a/1fc3dba0c4923c2a76e1ff0d52b305c44606da63f718d14d3231e21c51b0/s3transfer-0.2.1-py2.py3-none-any.whl (70kB)
166 Collecting PyYAML<5.2,>=3.10; python_version != "2.6" and python_version != "3.3" (from awscli)
167   Downloading https://mirrors.aliyun.com/pypi/packages/e3/e8/b3212641ee2718d556df0f23f78de8303f068fe29cdaa7a91018849582fe/PyYAML-5.1.2.tar.gz (265kB)
168 Collecting botocore==1.13.25 (from awscli)
169   Downloading https://mirrors.aliyun.com/pypi/packages/92/93/8a592d3be76ef6b9dba1c97b0139a0b2cabf4185692fd5c4938feea71d85/botocore-1.13.25-py2.py3-none-any.whl (5.6MB)
170 Collecting colorama<0.4.2,>=0.2.5; python_version != "2.6" and python_version != "3.3" (from awscli)
171   Downloading https://mirrors.aliyun.com/pypi/packages/4f/a6/728666f39bfff1719fc94c481890b2106837da9318031f71a8424b662e12/colorama-0.4.1-py2.py3-none-any.whl
172 Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)
173   Downloading https://mirrors.aliyun.com/pypi/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77kB)
174 Collecting python-dateutil<2.8.1,>=2.1; python_version >= "2.7" (from botocore==1.13.25->awscli)
175   Downloading https://mirrors.aliyun.com/pypi/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
176 Collecting urllib3<1.26,>=1.20; python_version >= "3.4" (from botocore==1.13.25->awscli)
177   Downloading https://mirrors.aliyun.com/pypi/packages/b4/40/a9837291310ee1ccc242ceb6ebfd9eb21539649f193a7c8c86ba15b98539/urllib3-1.25.7-py2.py3-none-any.whl (125kB)
178 Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.13.25->awscli)
179   Downloading https://mirrors.aliyun.com/pypi/packages/83/94/7179c3832a6d45b266ddb2aac329e101367fbdb11f425f13771d27f225bb/jmespath-0.9.4-py2.py3-none-any.whl
180 Collecting six>=1.5 (from python-dateutil<2.8.1,>=2.1; python_version >= "2.7"->botocore==1.13.25->awscli)
181   Downloading https://mirrors.aliyun.com/pypi/packages/65/26/32b8464df2a97e6dd1b656ed26b2c194606c16fe163c695a992b36c11cdf/six-1.13.0-py2.py3-none-any.whl
182 Building wheels for collected packages: PyYAML
183   Building wheel for PyYAML (setup.py): started
184   Building wheel for PyYAML (setup.py): finished with status 'done'
185   Stored in directory: /root/.cache/pip/wheels/f1/62/c9/f61bd2c2ae2f87b452a27f973b222d0b18626e3354aa150ca2
186 Successfully built PyYAML
187 Installing collected packages: pyasn1, rsa, docutils, six, python-dateutil, urllib3, jmespath, botocore, s3transfer, PyYAML, colorama, awscli
188 Successfully installed PyYAML-5.1.2 awscli-1.16.289 botocore-1.13.25 colorama-0.4.1 docutils-0.15.2 jmespath-0.9.4 pyasn1-0.4.8 python-dateutil-2.8.0 rsa-3.4.2 s3transfer-0.2.1 six-1.13.0 urllib3-1.25.7
189 WARNING: You are using pip version 19.1.1, however version 19.3.1 is available.
190 You should consider upgrading via the 'pip install --upgrade pip' command.
191   
192 [Container] 2019/11/22 03:57:21 Phase complete: INSTALL State: SUCCEEDED
193 [Container] 2019/11/22 03:57:21 Phase context status code:  Message: 
194 [Container] 2019/11/22 03:57:21 Entering phase PRE_BUILD
195 [Container] 2019/11/22 03:57:21 Running command echo Logging in to Amazon ECR...
196 Logging in to Amazon ECR...
197   
198 [Container] 2019/11/22 03:57:21 Running command $(aws ecr get-login --no-include-email --region cn-northwest-1)
199 WARNING! Using --password via the CLI is insecure. Use --password-stdin.
200 WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
201 Configure a credential helper to remove this warning. See
202 https://docs.docker.com/engine/reference/commandline/login/#credentials-store
203   
204 Login Succeeded
205   
206 [Container] 2019/11/22 03:57:22 Phase complete: PRE_BUILD State: SUCCEEDED
207 [Container] 2019/11/22 03:57:22 Phase context status code:  Message: 
208 [Container] 2019/11/22 03:57:22 Entering phase BUILD
209 [Container] 2019/11/22 03:57:22 Running command echo Build started on `date`
210 Build started on Fri Nov 22 03:57:22 UTC 2019
211   
212 [Container] 2019/11/22 03:57:22 Running command echo Building the Docker image...
213 Building the Docker image...
214   
215 [Container] 2019/11/22 03:57:22 Running command export GOPATH=`pwd`
216   
217 [Container] 2019/11/22 03:57:22 Running command go build -o ./docker/main ./src/main.go
218   
219 [Container] 2019/11/22 03:57:39 Running command echo Build completed on `date`
220 Build completed on Fri Nov 22 03:57:39 UTC 2019
221   
222 [Container] 2019/11/22 03:57:39 Phase complete: BUILD State: SUCCEEDED
223 [Container] 2019/11/22 03:57:39 Phase context status code:  Message: 
224 [Container] 2019/11/22 03:57:39 Entering phase POST_BUILD
225 [Container] 2019/11/22 03:57:39 Running command tree .
226 .
227 ├── __MACOSX
228 │·· └── docker
229 ├── buildspec.yml
230 ├── docker
231 │·· ├── CentOS-Base.repo
232 │·· ├── Dockerfile
233 │·· └── main
234 └── src
235     ├── github.com
236     │·· ├── astaxie
237     │·· │·· └── beego
238     │·· │··     ├── CONTRIBUTING.md
239     │·· │··     ├── LICENSE
240     │·· │··     ├── README.md
241     │·· │··     ├── admin.go
242     │·· │··     ├── admin_test.go
243     │·· │··     ├── adminui.go
244     │·· │··     ├── app.go
245     │·· │··     ├── beego.go
246     │·· │··     ├── cache
247     │·· │··     │·· ├── README.md
248     │·· │··     │·· ├── cache.go
249     │·· │··     │·· ├── cache_test.go
250     │·· │··     │·· ├── conv.go
251     │·· │··     │·· ├── conv_test.go
252     │·· │··     │·· ├── file.go
253     │·· │··     │·· ├── memcache
254     │·· │··     │·· │·· ├── memcache.go
255     │·· │··     │·· │·· └── memcache_test.go
256     │·· │··     │·· ├── memory.go
257     │·· │··     │·· ├── redis
258     │·· │··     │·· │·· ├── redis.go
259     │·· │··     │·· │·· └── redis_test.go
260     │·· │··     │·· └── ssdb
261     │·· │··     │··     ├── ssdb.go
262     │·· │··     │··     └── ssdb_test.go
263     │·· │··     ├── config
264     │·· │··     │·· ├── config.go
265     │·· │··     │·· ├── config_test.go
266     │·· │··     │·· ├── env
267     │·· │··     │·· │·· ├── env.go
268     │·· │··     │·· │·· └── env_test.go
269     │·· │··     │·· ├── fake.go
270     │·· │··     │·· ├── ini.go
271     │·· │··     │·· ├── ini_test.go
272     │·· │··     │·· ├── json.go
273     │·· │··     │·· ├── json_test.go
274     │·· │··     │·· ├── xml
275     │·· │··     │·· │·· ├── xml.go
276     │·· │··     │·· │·· └── xml_test.go
277     │·· │··     │·· └── yaml
278     │·· │··     │··     ├── yaml.go
279     │·· │··     │··     └── yaml_test.go
280     │·· │··     ├── config.go
281     │·· │··     ├── config_test.go
282     │·· │··     ├── context
283     │·· │··     │·· ├── acceptencoder.go
284     │·· │··     │·· ├── acceptencoder_test.go
285     │·· │··     │·· ├── context.go
286     │·· │··     │·· ├── context_test.go
287     │·· │··     │·· ├── input.go
288     │·· │··     │·· ├── input_test.go
289     │·· │··     │·· ├── output.go
290     │·· │··     │·· ├── param
291     │·· │··     │·· │·· ├── conv.go
292     │·· │··     │·· │·· ├── methodparams.go
293     │·· │··     │·· │·· ├── options.go
294     │·· │··     │·· │·· ├── parsers.go
295     │·· │··     │·· │·· └── parsers_test.go
296     │·· │··     │·· ├── renderer.go
297     │·· │··     │·· └── response.go
298     │·· │··     ├── controller.go
299     │·· │··     ├── controller_test.go
300     │·· │··     ├── doc.go
301     │·· │··     ├── error.go
302     │·· │··     ├── error_test.go
303     │·· │··     ├── filter.go
304     │·· │··     ├── filter_test.go
305     │·· │··     ├── flash.go
306     │·· │··     ├── flash_test.go
307     │·· │··     ├── fs.go
308     │·· │··     ├── go.mod
309     │·· │··     ├── go.sum
310     │·· │··     ├── grace
311     │·· │··     │·· ├── grace.go
312     │·· │··     │·· └── server.go
313     │·· │··     ├── hooks.go
314     │·· │··     ├── httplib
315     │·· │··     │·· ├── README.md
316     │·· │··     │·· ├── httplib.go
317     │·· │··     │·· └── httplib_test.go
318     │·· │··     ├── log.go
319     │·· │··     ├── logs
320     │·· │··     │·· ├── README.md
321     │·· │··     │·· ├── accesslog.go
322     │·· │··     │·· ├── alils
323     │·· │··     │·· │·· ├── alils.go
324     │·· │··     │·· │·· ├── config.go
325     │·· │··     │·· │·· ├── log.pb.go
326     │·· │··     │·· │·· ├── log_config.go
327     │·· │··     │·· │·· ├── log_project.go
328     │·· │··     │·· │·· ├── log_store.go
329     │·· │··     │·· │·· ├── machine_group.go
330     │·· │··     │·· │·· ├── request.go
331     │·· │··     │·· │·· └── signature.go
332     │·· │··     │·· ├── conn.go
333     │·· │··     │·· ├── conn_test.go
334     │·· │··     │·· ├── console.go
335     │·· │··     │·· ├── console_test.go
336     │·· │··     │·· ├── es
337     │·· │··     │·· │·· └── es.go
338     │·· │··     │·· ├── file.go
339     │·· │··     │·· ├── file_test.go
340     │·· │··     │·· ├── jianliao.go
341     │·· │··     │·· ├── log.go
342     │·· │··     │·· ├── logger.go
343     │·· │··     │·· ├── logger_test.go
344     │·· │··     │·· ├── multifile.go
345     │·· │··     │·· ├── multifile_test.go
346     │·· │··     │·· ├── slack.go
347     │·· │··     │·· ├── smtp.go
348     │·· │··     │·· └── smtp_test.go
349     │·· │··     ├── migration
350     │·· │··     │·· ├── ddl.go
351     │·· │··     │·· ├── doc.go
352     │·· │··     │·· └── migration.go
353     │·· │··     ├── mime.go
354     │·· │··     ├── namespace.go
355     │·· │··     ├── namespace_test.go
356     │·· │··     ├── orm
357     │·· │··     │·· ├── README.md
358     │·· │··     │·· ├── cmd.go
359     │·· │··     │·· ├── cmd_utils.go
360     │·· │··     │·· ├── db.go
361     │·· │··     │·· ├── db_alias.go
362     │·· │··     │·· ├── db_mysql.go
363     │·· │··     │·· ├── db_oracle.go
364     │·· │··     │·· ├── db_postgres.go
365     │·· │··     │·· ├── db_sqlite.go
366     │·· │··     │·· ├── db_tables.go
367     │·· │··     │·· ├── db_tidb.go
368     │·· │··     │·· ├── db_utils.go
369     │·· │··     │·· ├── models.go
370     │·· │··     │·· ├── models_boot.go
371     │·· │··     │·· ├── models_fields.go
372     │·· │··     │·· ├── models_info_f.go
373     │·· │··     │·· ├── models_info_m.go
374     │·· │··     │·· ├── models_test.go
375     │·· │··     │·· ├── models_utils.go
376     │·· │··     │·· ├── orm.go
377     │·· │··     │·· ├── orm_conds.go
378     │·· │··     │·· ├── orm_log.go
379     │·· │··     │·· ├── orm_object.go
380     │·· │··     │·· ├── orm_querym2m.go
381     │·· │··     │·· ├── orm_queryset.go
382     │·· │··     │·· ├── orm_raw.go
383     │·· │··     │·· ├── orm_test.go
384     │·· │··     │·· ├── qb.go
385     │·· │··     │·· ├── qb_mysql.go
386     │·· │··     │·· ├── qb_tidb.go
387     │·· │··     │·· ├── types.go
388     │·· │··     │·· ├── utils.go
389     │·· │··     │·· └── utils_test.go
390     │·· │··     ├── parser.go
391     │·· │··     ├── plugins
392     │·· │··     │·· ├── apiauth
393     │·· │··     │·· │·· ├── apiauth.go
394     │·· │··     │·· │·· └── apiauth_test.go
395     │·· │··     │·· ├── auth
396     │·· │··     │·· │·· └── basic.go
397     │·· │··     │·· ├── authz
398     │·· │··     │·· │·· ├── authz.go
399     │·· │··     │·· │·· ├── authz_model.conf
400     │·· │··     │·· │·· ├── authz_policy.csv
401     │·· │··     │·· │·· └── authz_test.go
402     │·· │··     │·· └── cors
403     │·· │··     │··     ├── cors.go
404     │·· │··     │··     └── cors_test.go
405     │·· │··     ├── policy.go
406     │·· │··     ├── router.go
407     │·· │··     ├── router_test.go
408     │·· │··     ├── session
409     │·· │··     │·· ├── README.md
410     │·· │··     │·· ├── couchbase
411     │·· │··     │·· │·· └── sess_couchbase.go
412     │·· │··     │·· ├── ledis
413     │·· │··     │·· │·· └── ledis_session.go
414     │·· │··     │·· ├── memcache
415     │·· │··     │·· │·· └── sess_memcache.go
416     │·· │··     │·· ├── mysql
417     │·· │··     │·· │·· └── sess_mysql.go
418     │·· │··     │·· ├── postgres
419     │·· │··     │·· │·· └── sess_postgresql.go
420     │·· │··     │·· ├── redis
421     │·· │··     │·· │·· └── sess_redis.go
422     │·· │··     │·· ├── redis_cluster
423     │·· │··     │·· │·· └── redis_cluster.go
424     │·· │··     │·· ├── redis_sentinel
425     │·· │··     │·· │·· ├── sess_redis_sentinel.go
426     │·· │··     │·· │·· └── sess_redis_sentinel_test.go
427     │·· │··     │·· ├── sess_cookie.go
428     │·· │··     │·· ├── sess_cookie_test.go
429     │·· │··     │·· ├── sess_file.go
430     │·· │··     │·· ├── sess_mem.go
431     │·· │··     │·· ├── sess_mem_test.go
432     │·· │··     │·· ├── sess_test.go
433     │·· │··     │·· ├── sess_utils.go
434     │·· │··     │·· ├── session.go
435     │·· │··     │·· └── ssdb
436     │·· │··     │··     └── sess_ssdb.go
437     │·· │··     ├── staticfile.go
438     │·· │··     ├── staticfile_test.go
439     │·· │··     ├── swagger
440     │·· │··     │·· └── swagger.go
441     │·· │··     ├── template.go
442     │·· │··     ├── template_test.go
443     │·· │··     ├── templatefunc.go
444     │·· │··     ├── templatefunc_test.go
445     │·· │··     ├── testdata
446     │·· │··     │·· ├── Makefile
447     │·· │··     │·· ├── bindata.go
448     │·· │··     │·· └── views
449     │·· │··     │··     ├── blocks
450     │·· │··     │··     │·· └── block.tpl
451     │·· │··     │··     ├── header.tpl
452     │·· │··     │··     └── index.tpl
453     │·· │··     ├── testing
454     │·· │··     │·· ├── assertions.go
455     │·· │··     │·· └── client.go
456     │·· │··     ├── toolbox
457     │·· │··     │·· ├── healthcheck.go
458     │·· │··     │·· ├── profile.go
459     │·· │··     │·· ├── profile_test.go
460     │·· │··     │·· ├── statistics.go
461     │·· │··     │·· ├── statistics_test.go
462     │·· │··     │·· ├── task.go
463     │·· │··     │·· └── task_test.go
464     │·· │··     ├── tree.go
465     │·· │··     ├── tree_test.go
466     │·· │··     ├── unregroute_test.go
467     │·· │··     ├── utils
468     │·· │··     │·· ├── caller.go
469     │·· │··     │·· ├── caller_test.go
470     │·· │··     │·· ├── captcha
471     │·· │··     │·· │·· ├── LICENSE
472     │·· │··     │·· │·· ├── README.md
473     │·· │··     │·· │·· ├── captcha.go
474     │·· │··     │·· │·· ├── image.go
475     │·· │··     │·· │·· ├── image_test.go
476     │·· │··     │·· │·· ├── siprng.go
477     │·· │··     │·· │·· └── siprng_test.go
478     │·· │··     │·· ├── debug.go
479     │·· │··     │·· ├── debug_test.go
480     │·· │··     │·· ├── file.go
481     │·· │··     │·· ├── file_test.go
482     │·· │··     │·· ├── mail.go
483     │·· │··     │·· ├── mail_test.go
484     │·· │··     │·· ├── pagination
485     │·· │··     │·· │·· ├── controller.go
486     │·· │··     │·· │·· ├── doc.go
487     │·· │··     │·· │·· ├── paginator.go
488     │·· │··     │·· │·· └── utils.go
489     │·· │··     │·· ├── rand.go
490     │·· │··     │·· ├── rand_test.go
491     │·· │··     │·· ├── safemap.go
492     │·· │··     │·· ├── safemap_test.go
493     │·· │··     │·· ├── slice.go
494     │·· │··     │·· ├── slice_test.go
495     │·· │··     │·· ├── testdata
496     │·· │··     │·· │·· └── grepe.test
497     │·· │··     │·· ├── utils.go
498     │·· │··     │·· └── utils_test.go
499     │·· │··     ├── validation
500     │·· │··     │·· ├── README.md
501     │·· │··     │·· ├── util.go
502     │·· │··     │·· ├── util_test.go
503     │·· │··     │·· ├── validation.go
504     │·· │··     │·· ├── validation_test.go
505     │·· │··     │·· └── validators.go
506     │·· │··     └── vendor
507     │·· │··         ├── golang.org
508     │·· │··         │·· └── x
509     │·· │··         │··     └── crypto
510     │·· │··         │··         ├── LICENSE
511     │·· │··         │··         ├── PATENTS
512     │·· │··         │··         ├── acme
513     │·· │··         │··         │·· ├── acme.go
514     │·· │··         │··         │·· ├── autocert
515     │·· │··         │··         │·· │·· ├── autocert.go
516     │·· │··         │··         │·· │·· ├── cache.go
517     │·· │··         │··         │·· │·· ├── listener.go
518     │·· │··         │··         │·· │·· └── renewal.go
519     │·· │··         │··         │·· ├── http.go
520     │·· │··         │··         │·· ├── jws.go
521     │·· │··         │··         │·· └── types.go
522     │·· │··         │··         └── pbkdf2
523     │·· │··         │··             └── pbkdf2.go
524     │·· │··         ├── gopkg.in
525     │·· │··         │·· └── yaml.v2
526     │·· │··         │··     ├── LICENSE
527     │·· │··         │··     ├── LICENSE.libyaml
528     │·· │··         │··     ├── NOTICE
529     │·· │··         │··     ├── README.md
530     │·· │··         │··     ├── apic.go
531     │·· │··         │··     ├── decode.go
532     │·· │··         │··     ├── emitterc.go
533     │·· │··         │··     ├── encode.go
534     │·· │··         │··     ├── go.mod
535     │·· │··         │··     ├── parserc.go
536     │·· │··         │··     ├── readerc.go
537     │·· │··         │··     ├── resolve.go
538     │·· │··         │··     ├── scannerc.go
539     │·· │··         │··     ├── sorter.go
540     │·· │··         │··     ├── writerc.go
541     │·· │··         │··     ├── yaml.go
542     │·· │··         │··     ├── yamlh.go
543     │·· │··         │··     └── yamlprivateh.go
544     │·· │··         └── vendor.json
545     │·· └── shiena
546     │··     └── ansicolor
547     │··         ├── LICENSE
548     │··         ├── README.md
549     │··         ├── ansicolor
550     │··         │·· └── main.go
551     │··         ├── ansicolor.go
552     │··         ├── ansicolor_ansi.go
553     │··         ├── ansicolor_test.go
554     │··         ├── ansicolor_windows.go
555     │··         ├── ansicolor_windows_test.go
556     │··         ├── example_test.go
557     │··         └── export_test.go
558     └── main.go
559   
560 62 directories, 270 files
561   
562 [Container] 2019/11/22 03:57:39 Running command cd ./docker
563   
564 [Container] 2019/11/22 03:57:39 Running command echo Build completed on `date`
565 Build completed on Fri Nov 22 03:57:39 UTC 2019
566   
567 [Container] 2019/11/22 03:57:39 Running command echo Pushing the Docker image...
568 Pushing the Docker image...
569   
570 [Container] 2019/11/22 03:57:39 Running command docker build -t acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test:go .
571 Sending build context to Docker daemon  14.27MB
572   
573 Step 1/9 : FROM acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test:centos
574 centos: Pulling from liushuo-test
575 729ec3a6ada3: Pulling fs layer
576 729ec3a6ada3: Verifying Checksum
577 729ec3a6ada3: Download complete
578 729ec3a6ada3: Pull complete
579 Digest: sha256:6ab380c5a5acf71c1b6660d645d2cd79cc8ce91b38e0352cbf9561e050427baf
580 Status: Downloaded newer image for acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test:centos
581  ---> 0f3e07c0138f
582 Step 2/9 : LABEL maintainer="  <  @163.com>"
583  ---> Running in ff5084fd43c0
584 Removing intermediate container ff5084fd43c0
585  ---> 5b6c27eaa717
586 Step 3/9 : ADD CentOS-Base.repo /etc/yum.repos.d/
587  ---> d752afffc358
588 Step 4/9 : RUN yum clean all
589  ---> Running in 795574f63bcd
590 ·[91mRepository extras is listed more than once in the configuration
591 ·[0m·[91mRepository centosplus is listed more than once in the configuration
592 ·[0m0 files removed
593 Removing intermediate container 795574f63bcd
594  ---> 00cb97f55a0c
595 Step 5/9 : COPY main /app/
596  ---> 28c8ee6987b9
597 Step 6/9 : WORKDIR /app
598  ---> Running in b8598d0a2886
599 Removing intermediate container b8598d0a2886
600  ---> 721e40e7357d
601 Step 7/9 : RUN chmod +x main
602  ---> Running in 80554b499fc9
603 Removing intermediate container 80554b499fc9
604  ---> 5f2c98d39490
605 Step 8/9 : EXPOSE 8000
606  ---> Running in 70c4f9824273
607 Removing intermediate container 70c4f9824273
608  ---> 770d0c033ba4
609 Step 9/9 : CMD ["./main"]
610  ---> Running in fa8f32d74604
611 Removing intermediate container fa8f32d74604
612  ---> ba988e8d4328
613 Successfully built ba988e8d4328
614 Successfully tagged acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test:go
615   
616 [Container] 2019/11/22 03:57:52 Running command docker images
617 REPOSITORY                                                          TAG                 IMAGE ID            CREATED                  SIZE
618 acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test   go                  ba988e8d4328        Less than a second ago   249MB
619 acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test   centos              0f3e07c0138f        7 weeks ago              220MB
620   
621 [Container] 2019/11/22 03:57:52 Running command docker push acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test:go
622 The push refers to repository [acountid.dkr.ecr.cn-northwest-1.amazonaws.com.cn/liushuo-test]
623 47ba8e3392ef: Preparing
624 07cf17b9e96a: Preparing
625 8fc555f91cf4: Preparing
626 ccc954a5c555: Preparing
627 9e607bb861a7: Preparing
628 9e607bb861a7: Layer already exists
629 ccc954a5c555: Pushed
630 8fc555f91cf4: Pushed
631 47ba8e3392ef: Pushed
632 07cf17b9e96a: Pushed
633 go: digest: sha256:ac3c735425706148e28bd46a68c01e368ff5c15bef8c9d9374c7d369002df49e size: 1367
634   
635 [Container] 2019/11/22 03:57:55 Running command echo done
636 done
637   
638 [Container] 2019/11/22 03:57:55 Phase complete: POST_BUILD State: SUCCEEDED
639 [Container] 2019/11/22 03:57:55 Phase context status code:  Message: 
640 [Container] 2019/11/22 03:57:55 Expanding base directory path: .
641 [Container] 2019/11/22 03:57:55 Assembling file list
642 [Container] 2019/11/22 03:57:55 Expanding .
643 [Container] 2019/11/22 03:57:55 Expanding file paths for base directory .
644 [Container] 2019/11/22 03:57:55 Assembling file list
645 [Container] 2019/11/22 03:57:55 Expanding docker/main
646 [Container] 2019/11/22 03:57:55 Found 1 file(s)
647 [Container] 2019/11/22 03:57:56 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
648 [Container] 2019/11/22 03:57:56 Phase context status code:  Message:
构建日志

 

运行结果

 1 {
 2     "Version": "2012-10-17",
 3     "Statement": [
 4         {
 5             "Effect": "Allow",
 6             "Resource": [
 7                 "arn:aws-cn:s3:::liushuo--test/*"
 8             ],
 9             "Action": [
10                 "s3:PutObject",
11                 "s3:GetObject",
12                 "s3:GetObjectVersion",
13                 "s3:GetBucketAcl",
14                 "s3:GetBucketLocation",
15                 "s3:ListBucket",
16             ]
17         },
18  
19         {
20             "Effect": "Allow",
21             "Action": [
22                 "cloudwatch:PutMetricData",
23                 "ds:CreateComputer",
24                 "ds:DescribeDirectories",
25                 "ec2:DescribeInstanceStatus",
26                 "logs:*",
27                 "ssm:*",
28                 "ec2messages:*"
29             ],
30             "Resource": "*"
31         },
32         {
33             "Effect": "Allow",
34             "Action": "iam:CreateServiceLinkedRole",
35             "Resource": "arn:aws-cn:iam::*:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM*",
36             "Condition": {
37                 "StringLike": {
38                     "iam:AWSServiceName": "ssm.amazonaws.com"
39                 }
40             }
41         },
42         {
43             "Effect": "Allow",
44             "Action": [
45                 "iam:DeleteServiceLinkedRole",
46                 "iam:GetServiceLinkedRoleDeletionStatus"
47             ],
48             "Resource": "arn:aws-cn:iam::*:role/aws-service-role/ssm.amazonaws.com/AWSServiceRoleForAmazonSSM*"
49         },
50         {
51             "Effect": "Allow",
52             "Action": [
53                 "ssmmessages:CreateControlChannel",
54                 "ssmmessages:CreateDataChannel",
55                 "ssmmessages:OpenControlChannel",
56                 "ssmmessages:OpenDataChannel"
57             ],
58             "Resource": "*"
59         },
60         {
61             "Sid": "VisualEditor0",
62             "Effect": "Allow",
63             "Action": [
64                 "ecr:CompleteLayerUpload",
65                 "ecr:GetAuthorizationToken",
66                 "ecr:UploadLayerPart",
67                 "ecr:InitiateLayerUpload",
68                 "ecr:BatchCheckLayerAvailability",
69                 "ecr:PutImage"
70             ],
71             "Resource": "*"
72         },
73         {
74             "Effect": "Allow",
75             "Resource": "*",
76             "Action": [
77                 "logs:CreateLogGroup",
78                 "logs:CreateLogStream",
79                 "logs:PutLogEvents"
80             ]
81         }
82  
83     ]
84 }
codebuild角色完整的权限

 

3、ecs

3.1、创建集群

步骤一、选择集群模板

选择EC2 Linux + 联网。  不选(fargate,没权限)

步骤二、配置集群

在选择VPC时,如果配置了ALB的话,选择相同的VPC

3.2、任务定义

在选择类型时:选择EC2

需要填写的字段

任务定义名称:

任务角色:默认的

任务执行角色:默认的

任务内存:

任务CPU单元

添加容器

      容器名称

       映像

3.3、创建ecs服务

启动类型  选择ec2

任务定义选择刚刚创建的,修订选择latest

服务类型选择 replica

负载均衡类型:

      可以选择无、alb

 

①无,通过EC2实例的EIP进行访问

②ALB,可以通过EC2实例的EIP进行访问;也可以通过ALB的域名进行访问

注意

1、为什么要使用ecr

     如果不使用ecr,编译dockerfile时所使用的的基础镜像会从docker hub拉取,由于网络环境非常慢。因此提前将所需的image上传到ecr,利用aws的内部网络,加速pull。

2、要注意使用ALB时,ecs所启动的ec2实例必须是注册在目标组里且正常的。

posted @ 2019-11-22 17:35  慕沁  阅读(487)  评论(0)    收藏  举报