Merge branch 'express-final'

This commit is contained in:
Sameer Naik
2017-01-18 11:39:54 +05:30
9 changed files with 111 additions and 33 deletions
+2
View File
@@ -0,0 +1,2 @@
.git/
.gitignore
+3 -2
View File
@@ -15,16 +15,17 @@ RUN npm install -g bower@1.8.0 sequelize-cli
# Install express
RUN bitnami-pkg install express-4.14.0-1 --checksum f98a7f8e85d038bb895d1105f6a0d995810b004f78b4fc0a0299237dc5070795
RUN rm -rf /app
# ExpressJS template
ENV BITNAMI_APP_NAME=express
ENV BITNAMI_IMAGE_VERSION=4.14.0-r15
ENV BITNAMI_IMAGE_VERSION=4.14.0-r16
COPY rootfs/ /
# The extra files that we bundle should use the Bitnami User
# so the entrypoint does not have any permission issues
RUN chown -R bitnami: /app /dist
RUN mkdir /app && chown bitnami: /app /dist
USER bitnami
+18 -1
View File
@@ -105,6 +105,24 @@ Express by default does not require a database connection to work but we provide
You can use [Mongoose](http://mongoosejs.com/) ODM in your application to model your application data.
## Going to Production
The Express Development Container generates a Dockerfile in your working directory. This can be used to create a production-ready container image consisting of your application code and its dependencies.
1. Build your Docker image
```bash
$ docker build -t myregistry/myapp:1.0.0
```
2. Push to an image registry
```bash
$ docker push myregistry/myapp:1.0.0
```
3. Update orchestration files to reference the pushed image
## Issues
If you encountered a problem running this container, you can file an [issue](../../issues/new). For us to provide better support, be sure to include the following information in your issue:
@@ -130,4 +148,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
@@ -14,6 +14,10 @@ services:
- PORT=3000
- NODE_ENV=development
- DATABASE_URL=mysql://root@mariadb/myapp
- SKIP_DB_WAIT=0
- SKIP_DB_MIGRATION=0
- SKIP_NPM_INSTALL=0
depends_on:
- mariadb
ports:
@@ -14,6 +14,10 @@ services:
- PORT=3000
- NODE_ENV=development
- DATABASE_URL=postgres://postgres@postgresql/myapp
- SKIP_DB_WAIT=0
- SKIP_DB_MIGRATION=0
- SKIP_NPM_INSTALL=0
depends_on:
- postgresql
ports:
+4
View File
@@ -12,6 +12,10 @@ services:
- PORT=3000
- NODE_ENV=development
- DATABASE_URL=mongodb://mongodb:27017/myapp
- SKIP_DB_WAIT=0
- SKIP_DB_MIGRATION=0
- SKIP_NPM_INSTALL=0
depends_on:
- mongodb
ports:
+50 -30
View File
@@ -43,35 +43,64 @@ __wait_for_db() {
}
wait_for_db() {
if getent hosts mongodb >/dev/null; then
__wait_for_db mongodb 27017
fi
if ! [[ -n $SKIP_DB_WAIT && $SKIP_DB_WAIT -gt 0 ]] && database_tier_exists ; then
if getent hosts mongodb >/dev/null; then
__wait_for_db mongodb 27017
fi
if getent hosts mariadb >/dev/null; then
__wait_for_db mariadb 3306
fi
if getent hosts mariadb >/dev/null; then
__wait_for_db mariadb 3306
fi
if getent hosts postgresql >/dev/null; then
__wait_for_db postgresql 5432
if getent hosts postgresql >/dev/null; then
__wait_for_db postgresql 5432
fi
fi
}
add_database_support() {
if getent hosts mongodb >/dev/null && ! npm ls mongodb >/dev/null; then
npm install --save mongodb
if database_tier_exists; then
if getent hosts mongodb >/dev/null && ! npm ls mongodb >/dev/null; then
npm install --save mongodb
fi
if getent hosts mariadb >/dev/null && ! npm ls mysql >/dev/null; then
npm install --save mysql
fi
if getent hosts postgresql >/dev/null && ! npm ls pg pg-hstore >/dev/null; then
npm install --save pg pg-hstore
fi
fi
}
add_sample_code() {
if ! [[ -n $SKIP_SAMPLE_CODE && $SKIP_SAMPLE_CODE -gt 0 ]]; then
log "Adding dist samples"
cp -r /dist/samples .
fi
}
add_dockerfile() {
if [[ ! -f Dockerfile ]]; then
cp -r /dist/Dockerfile.tpl Dockerfile
sed -i 's/{{BITNAMI_IMAGE_VERSION}}/'"$BITNAMI_IMAGE_VERSION"'/g' Dockerfile
fi
if getent hosts mariadb >/dev/null && ! npm ls mysql >/dev/null; then
npm install --save mysql
if [[ ! -f .dockerignore ]]; then
cp -r /dist/.dockerignore .
fi
}
if getent hosts postgresql >/dev/null && ! npm ls pg pg-hstore >/dev/null; then
npm install --save pg pg-hstore
npm_install() {
if ! [[ -n $SKIP_NPM_INSTALL && $SKIP_NPM_INSTALL -gt 0 ]] && [[ -f package.json ]] && ! dependencies_up_to_date; then
log "Installing/Updating Express dependencies (npm)"
npm install
fi
}
migrate_db() {
if [ -f .sequelizerc ]; then
if ! [[ -n $SKIP_DB_MIGRATE && $SKIP_DB_MIGRATE -gt 0 ]] && [[ -f .sequelizerc ]]; then
log "Applying database migrations (sequelize db:migrate)"
sequelize db:migrate
fi
@@ -82,27 +111,18 @@ log () {
}
if [ "$1" == npm ] && [ "$2" == "start" -o "$2" == "run" ]; then
if database_tier_exists; then
wait_for_db
fi
wait_for_db
if ! app_present; then
log "Creating express application"
express . -f
if database_tier_exists; then
add_database_support
fi
log "Adding dist samples"
cp -r /dist/samples .
add_database_support
add_sample_code
fi
if ! dependencies_up_to_date; then
log "Installing/Updating Express dependencies (npm)"
npm install
log "Dependencies updated"
fi
add_dockerfile
npm_install
if ! fresh_container; then
echo "#########################################################################"
+5
View File
@@ -0,0 +1,5 @@
.git/
node_modules/
.gitignore
docker-compose.yml
+21
View File
@@ -0,0 +1,21 @@
## Dockerfile for building production image
FROM bitnami/express:{{BITNAMI_IMAGE_VERSION}}
MAINTAINER john.smith@acme.com
ENV DISABLE_WELCOME_MESSAGE=1
ENV NODE_ENV=production \
PORT=3000
# Skip fetching dependencies and database migrations for production image
ENV SKIP_DB_WAIT=0 \
SKIP_DB_MIGRATION=1 \
SKIP_NPM_INSTALL=1
COPY . /app
RUN sudo chown -R bitnami: /app
RUN npm install
EXPOSE 3000
CMD ["npm", "start"]