Difference between revisions of "IT-SDK-Angular"
Jump to navigation
Jump to search
(→Angular-CLI Options) |
|||
| Line 17: | Line 17: | ||
serve : Builds and Serves the app. | serve : Builds and Serves the app. | ||
deploy : Invokes the builder for a specified project. | deploy : Invokes the builder for a specified project. | ||
| + | </pre> | ||
| + | |||
| + | ==Docker-File== | ||
| + | <pre class="code"> | ||
| + | FROM node:12.2.0 as build | ||
| + | #------------------------------ | ||
| + | # install chrome for protractor tests | ||
| + | RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - | ||
| + | RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' | ||
| + | RUN apt-get update && apt-get install -yq google-chrome-stable | ||
| + | #------------------------------ | ||
| + | WORKDIR /app # set working directory | ||
| + | ENV PATH /app/node_modules/.bin:$PATH # add `/app/node_modules/.bin` to $PATH | ||
| + | #--------------------------------------# install and cache app dependencies | ||
| + | COPY package.json /app/package.json | ||
| + | RUN npm install | ||
| + | RUN npm install -g @angular/cli@7.3.9 | ||
| + | COPY . /app | ||
| + | # run tests | ||
| + | RUN ng test --watch=false | ||
| + | RUN ng e2e --port 4202 | ||
| + | # generate build | ||
| + | RUN ng build --output-path=dist | ||
| + | ############ | ||
| + | ### prod ### | ||
| + | ############ | ||
| + | FROM nginx:1.16.0-alpine | ||
| + | # copy artifact build from the 'build environment' | ||
| + | COPY --from=build /app/dist /usr/share/nginx/html | ||
| + | |||
| + | EXPOSE 80 # expose port 80 | ||
| + | CMD ["nginx", "-g", "daemon off;"] # run nginx | ||
| + | </pre> | ||
| + | |||
| + | ==Docker-CMD== | ||
| + | <pre class="code"> | ||
| + | $ docker build -t angular-docker . | ||
| + | $ docker run -d -p 80:80 --env BACKEND_API_URL=yourApiUrl --env DEFAULT_LANGUAGE=de angular-docker | ||
</pre> | </pre> | ||
Revision as of 18:43, 3 December 2019
- Source: https://angular.io/docs
- Source: https://blog.codecentric.de/en/2019/03/docker-angular-dockerize-app-easily/
- Source: https://mherman.org/blog/dockerizing-an-angular-app/
- SRC: https://malcoded.com/posts/angular-docker/
- SRC: https://www.whitehorses.nl/blog/running-angular-application-docker-dummies
- Angular requires Node.js version 10.9.0 or later.
Life-Cycle: ng
$ npm install -g @angular/cli $ ng new my-app $ ng serve --open --port 4321
Angular-CLI Options
new : Greate new workspace. build : Compiles the app. serve : Builds and Serves the app. deploy : Invokes the builder for a specified project.
Docker-File
FROM node:12.2.0 as build #------------------------------ # install chrome for protractor tests RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' RUN apt-get update && apt-get install -yq google-chrome-stable #------------------------------ WORKDIR /app # set working directory ENV PATH /app/node_modules/.bin:$PATH # add `/app/node_modules/.bin` to $PATH #--------------------------------------# install and cache app dependencies COPY package.json /app/package.json RUN npm install RUN npm install -g @angular/cli@7.3.9 COPY . /app # run tests RUN ng test --watch=false RUN ng e2e --port 4202 # generate build RUN ng build --output-path=dist ############ ### prod ### ############ FROM nginx:1.16.0-alpine # copy artifact build from the 'build environment' COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 # expose port 80 CMD ["nginx", "-g", "daemon off;"] # run nginx
Docker-CMD
$ docker build -t angular-docker . $ docker run -d -p 80:80 --env BACKEND_API_URL=yourApiUrl --env DEFAULT_LANGUAGE=de angular-docker