Git Product home page Git Product logo

s2i-angular-container's Introduction

S2I Builder for Angular Apps

OpenShift S2I builder image for Angular apps using Angular CLI and Apache httpd 2.4.

Builder image contains a NodeJS / NPM environment to be able to build your Angular application using the angular cli (ng build --prod).

Additionally the apache httpd web container is used during runtime to statically serve the files generated during build phase.

S2I - Source 2 Image

You can directly invoke S2I builds from command line using the S2I binary.

This repository contains an angular app (ng new test-app) in the directory test/test-app that can be used for demo purpose. To build this demo app with S2i simply execute:

s2i build https://github.com/MrGoro/s2i-angular-container.git --context-dir=test/test-app/ schuermann/s2i-angular-container angular-sample-app
docker run -p 8080:8080 angular-sample-app

Incremental Builds

You can trigger incremental builds by specifying --incremental=true when building an image. Incremental builds provide the already installed node_modules directory from a previous build within a following build. This will dramatically speed up installation of NodeJS dependencies.

s2i build https://github.com/MrGoro/s2i-angular-container.git --incremental=true --context-dir=test/test-app/ schuermann/s2i-angular-container angular-sample-app
docker run -p 8080:8080 angular-sample-app

Use a different runtime image

For dynamic languages like PHP, Python, or Ruby, the build-time and run-time environments are the same. In this case using the builder as a base image for a resulting application image is natural.

For compiled languages like C, C++, Go, or Java, the dependencies necessary for compilation might dramatically outweigh the size of the actual runtime artifacts, or provide attack surface areas that are undesirable in an application image. See S2I Docs - How to use a non-builder image for the final application image.

The same applies to Angular Apps that are compiled using a full NodeJS / NPM environment and a lot of dependencies (node_modules). During runtime they are served as static web pages from a web container with no need for NodeJS, the application source and all dependencies.

To use a different image for runtime, you can do the following with S2I:

s2i build https://github.com/MrGoro/s2i-angular-container.git --context-dir=test/test-app/ schuermann/s2i-angular-container angular-sample-app --runtime-image <runtime-image> --runtime-artifact </path/to/artifact>

For example to run the built app using nginx you could use the following:

s2i build https://github.com/MrGoro/s2i-angular-container.git --context-dir=test/test-app/ schuermann/s2i-angular-container angular-sample-app --runtime-image nginx --runtime-artifact /opt/app-root/src:/usr/share/nginx/html

OpenShift

To use the builder image in your OpenShift environment you can import this simple image stream by creating the objects inside angular-s2i-httpd.json using the OC binary:

oc create -f angular-s2i-httpd.json

To make the image stream globally availiable use the namespace openshift

oc create -f angular-s2i-httpd.json -n openshift

Incremental Builds

To activate incremental builds in OpenShift, edit the build configuration (YAML) and insert incremental: true inside spec:strategy:sourceStrategy:

  strategy:
    type: Source
    sourceStrategy:
      from:
        kind: ImageStreamTag
        namespace: angular
        name: 'angular:latest'
      incremental: true

s2i-angular-container's People

Contributors

mrgoro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

s2i-angular-container's Issues

Build failing on Openshift but completing locally

HI thanks very much for your builder. I have been trying to get a build to complete on Openshift but it keeps failing with Generic build failed

When I build with s2i locally s2i build . schuermann/s2i-angular-container myapp it works flawlessly however when running on Openshift it will always fail halfway though a build. The logs of the build will show lines like

npm info addNameTag [ 'tsutils', 'latest' ]

> --
>   | npm info retry fetch attempt 1 at 3:37:34 PM
>   | npm info attempt registry request try #1 at 3:37:34 PM
>   | npm http fetch GET https://registry.npmjs.org/tsutils/-/tsutils-2.19.1.tgz
>   | npm http fetch 200 https://registry.npmjs.org/tsutils/-/tsutils-2.19.1.tgz
> 

I can't really tell if this is even an error. other than it appears to retry a download attempt, these lines I can see in the local s2i build aswell.

Any clues on where the issue maybe?

Thanks.

Possibly add a little more openshift instruction to readme?

I am still new to openshift, using my free openshift online starter I am not quite sure I am correctly using these s2i scripts with my angular-cli generated app. So far I created the imagestream, copied the Dockerfile and s2i folder into my repo (https://bitbucket.org/lpalnau/pet-zoo).

oc new-app https://bitbucket.org/lpalnau/pet-zoo.git
creates most of the pieces (service, deployment) I'd expect, but it fails to create the build config due to "build strategy Docker is not allowed"

λ oc new-app https://bitbucket.org/lpalnau/pet-zoo.git
--> Found Docker image bb81a09 (6 months old) from Docker Hub for "openshift/base-centos7"

    * An image stream will be created as "base-centos7:latest" that will track the source image
    * A Docker build using source code from https://bitbucket.org/lpalnau/pet-zoo.git will be created
      * The resulting image will be pushed to image stream "pet-zoo:latest"
      * Every time "base-centos7:latest" changes a new build will be triggered
      * WARNING: this source repository may require credentials.
                 Create a secret with your git credentials and use 'set build-secret' to assign it to the build config.
    * This image will be deployed in deployment config "pet-zoo"
    * Port 8080 will be load balanced by service "pet-zoo"
      * Other containers can access this service through the hostname "pet-zoo"
    * WARNING: Image "openshift/base-centos7" runs as the 'root' user which may not be permitted by your cluster administrator

--> Creating resources ...
    imagestream "base-centos7" created
    imagestream "pet-zoo" created
    error: buildconfigs "pet-zoo" is forbidden: build strategy Docker is not allowed
    deploymentconfig "pet-zoo" created
    service "pet-zoo" created
--> Failed

Thanks for any help you could provide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.