【发布时间】:2022-03-03 22:59:20
【问题描述】:
我尝试使用 Docker 映像在弹性 beanstalk 上创建环境。但是 Docker 映像需要大量内存进行部署。有办法减少吗?
它适用于“t2.medium”,但这对于节点项目来说太大了。我可以通过“t2.micro”处理吗?
EB 命令:
export MY_APP=my-app-node
export MY_ENV=my-environment-node
eb init $MY_APP -r $AWS_DEFAULT_REGION -p "Docker"
eb create $MY_ENV --single --instance-types t2.medium --envvars key1=val1 || echo "environment is already created."
eb deploy $MY_ENV -l v-${BUILD_NUM}
Dockerfile 是:
FROM node:alpine
COPY package.json ./
RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
WORKDIR /ng-app
COPY . .
## Build the angular app in production mode and store the artifacts in dist folder
RUN npm run config --configuration production && $(npm bin)/ng build --configuration production
FROM nginx:latest
## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
EXPOSE 80
COPY --from=0 /ng-app/dist/demo-ng /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
docker-compose.yml 文件:
version: '3.8'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "80:80"
env_file:
- .env
而 package.json 是:
{
"name": "demo-ng",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"config": "ts-node set-env.ts --configuration production",
"start": "ng serve --configuration production --port 8081",
"build": "ng build --configuration production --build-optimizer=true --aot=true --output-hashing=all --named-chunks=false --vendor-chunk=true",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "~12.0.0",
"@angular/common": "~12.0.0",
"@angular/compiler": "~12.0.0",
"@angular/core": "~12.0.0",
"@angular/forms": "~12.0.0",
"@angular/platform-browser": "~12.0.0",
"@angular/platform-browser-dynamic": "~12.0.0",
"@angular/router": "~12.0.0",
"@fortawesome/angular-fontawesome": "^0.9.0",
"@fortawesome/fontawesome-svg-core": "^1.2.35",
"@fortawesome/free-brands-svg-icons": "^5.15.3",
"@fortawesome/free-regular-svg-icons": "^5.15.3",
"@fortawesome/free-solid-svg-icons": "^5.15.3",
"bootstrap": "^5.0.1",
"jquery": "^3.6.0",
"popper.js": "^1.16.1",
"rxjs": "~6.6.0",
"ts-node": "^10.0.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4",
"dotenv": "^10.0.0",
"yargs": "^16.2.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.0.0",
"@angular/cli": "~12.0.0",
"@angular/compiler-cli": "~12.0.0",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.20.14",
"jasmine-core": "~3.7.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"typescript": "~4.2.3"
}
}
【问题讨论】:
标签: angular amazon-web-services docker amazon-elastic-beanstalk