├── .dockerignore ├── .travis.yml ├── Dockerfile ├── Dockerfile.test ├── LICENSE ├── Makefile ├── README.md ├── entry.sh ├── run-tests.sh └── test.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: bash 2 | 3 | sudo: required 4 | 5 | services: 6 | - docker 7 | 8 | script: 9 | - ./test.sh 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:latest 2 | 3 | MAINTAINER Andrew Cutler 4 | 5 | EXPOSE 3000 6 | 7 | ENV STRIDER_VERSION=v1.10.0 STRIDER_GIT_SRC=https://github.com/Strider-CD/strider.git STRIDER_HOME=/data STRIDER_SRC=/opt/strider 8 | ENV NODE_ENV production 9 | 10 | RUN useradd --comment "Strider CD" --home ${STRIDER_HOME} strider && mkdir -p ${STRIDER_HOME} && chown strider:strider ${STRIDER_HOME} 11 | VOLUME [ "$STRIDER_HOME" ] 12 | 13 | RUN mkdir -p $STRIDER_SRC && cd $STRIDER_SRC && \ 14 | # Checkout into $STRIDER_SRC 15 | git clone $STRIDER_GIT_SRC . && \ 16 | [ "$STRIDER_VERSION" != 'master' ] && git checkout tags/$STRIDER_VERSION || git checkout master && \ 17 | rm -rf .git && \ 18 | # Install NPM deps 19 | npm install && \ 20 | # FIX: https://github.com/Strider-CD/strider/pull/1056 21 | npm install morgan@1.5.0 &&\ 22 | # Create link to strider home dir so the modules can be used as a cache 23 | mv node_modules node_modules.cache && ln -s ${STRIDER_HOME}/node_modules node_modules && \ 24 | # Allow strider user to update .restart file 25 | chown strider:strider ${STRIDER_SRC}/.restart && \ 26 | # Cleanup Upstream cruft 27 | rm -rf /tmp/* 28 | 29 | ENV PATH ${STRIDER_SRC}/bin:$PATH 30 | 31 | COPY entry.sh / 32 | USER strider 33 | ENTRYPOINT ["/entry.sh"] 34 | CMD ["strider"] 35 | -------------------------------------------------------------------------------- /Dockerfile.test: -------------------------------------------------------------------------------- 1 | FROM jpetazzo/dind:latest 2 | ADD * /build/ 3 | WORKDIR /build 4 | CMD ["/build/run-tests.sh"] 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2018 Andrew Cutler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build nocache bash test run clean 2 | 3 | docker_tag = macropin/strider 4 | APP_HOST = localhost 5 | 6 | build: 7 | docker build -t $(docker_tag) . 8 | 9 | nocache: 10 | docker build --no-cache=true -t $(docker_tag) . 11 | 12 | bash: 13 | docker run --rm -it $(docker_tag) bash 14 | 15 | test: 16 | ./test.sh 17 | 18 | run: 19 | $(eval MONGO_ID := $(shell docker run -p 3000:3000 --name strider-mongo -d mongo)) 20 | $(eval STRIDER_ID := $(shell docker run --env STRIDER_ADMIN_EMAIL=admin@example.com --env STRIDER_ADMIN_PASSWORD=password --name strider-app --link strider-mongo:mongo -d ${docker_tag})) 21 | $(eval STRIDER_IP := $(shell docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${STRIDER_ID})) 22 | @echo "Running ${STRIDER_ID} @ http://${STRIDER_IP}:3000" 23 | @echo "Running ${MONGO_ID} MongoDB" 24 | @docker attach ${STRIDER_ID} 25 | @docker kill ${STRIDER_ID} ${MONGO_ID} 26 | @docker rm ${STRIDER_ID} ${MONGO_ID} 27 | 28 | clean: 29 | @docker ps -a | grep strider | awk '{ print $$1 }' | xargs -r docker rm -f 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Strider-CD Docker 2 | 3 | [![Build Status](https://travis-ci.org/macropin/docker-strider.svg?branch=master)](https://travis-ci.org/macropin/docker-strider) 4 | 5 | Possibly the best `Dockerfile` for [Strider-CD](https://github.com/Strider-CD/strider). 6 | 7 | ## Features 8 | 9 | - Uses [node](https://registry.hub.docker.com/_/node/) base image 10 | - Doesn't run as root 11 | - Thin and Optimised Container. Uses linked [MongoDB](https://registry.hub.docker.com/_/mongo/) and [SMTP](https://registry.hub.docker.com/u/panubo/postfix/) containers for those services 12 | - Installs latest Strider-CD cleanly from Git source 13 | - Supports installing and upgrading plugins from the web UI. 14 | 15 | ## Usage 16 | 17 | The most straight forward usage is via Docker links: 18 | 19 | ``` 20 | docker run -d --name mongo mongo 21 | docker run -d --name smtp -e MAILNAME=test panubo/postfix 22 | docker run -d --name strider -p 3000:3000 --link mongo --link smtp docker.io/macropin/strider:latest 23 | ``` 24 | 25 | Then go point your browser at `http://localhost:3000`. 26 | 27 | ## Environment variables 28 | 29 | These are the base Strider variables. Docker links can be use in place of configuring the SMTP and MongoDB services: 30 | 31 | - `SERVER_NAME` - Required; Address at which server will be accessible on the Internet. E.g. https://strider.example.com (note: no trailing slash) 32 | - `HOST` - Host where strider listens, optional (defaults to 0.0.0.0). 33 | - `PORT` - Port that strider runs on, optional (defaults to 3000). 34 | - `DB_URI` - MongoDB DB URI (or use `--link MONGO`), alternatively define both `MONGO_HOST` and `MONGO_PORT` 35 | - `HTTP_PROXY` - Proxy support, optional (defaults to null) 36 | If you want email notifications, configure an SMTP server (we recommend Mailgun for SMTP if you need a server - free account gives 200 emails / day): 37 | - `SMTP_HOST` - SMTP server hostname e.g. smtp.example.com 38 | - `SMTP_PORT` - SMTP server port e.g. 587 (default) 39 | - `SMTP_USER` - SMTP auth username e.g. "myuser" 40 | - `SMTP_PASS` - SMTP auth password e.g. "supersecret" 41 | - `SMTP_FROM` - Default FROM address e.g. "Strider noreply@stridercd.com" (default) 42 | 43 | Initial config variables. If these are defined then they will be used to create an admin account: 44 | 45 | - `STRIDER_ADMIN_EMAIL` 46 | - `STRIDER_ADMIN_PASSWORD` 47 | 48 | ## Status 49 | 50 | Stable. 51 | -------------------------------------------------------------------------------- /entry.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | [ "$DEBUG" == 'true' ] && set -x 6 | 7 | # Allow bypass initialisation 8 | if [ "$1" != "strider" ]; then 9 | exec "$@" 10 | fi 11 | 12 | echo ">> Strider Docker Image $STRIDER_VERSION Starting..." 13 | 14 | # Check that MONGO variables are defined 15 | if [ -z "${MONGO_PORT_27017_TCP_ADDR}" -a -z "${MONGO_HOST}" -a -z "$DB_URI" ]; then 16 | echo "You must link this container with MONGO or define MONGO_HOST or DB_URI" 17 | exit 1 18 | fi 19 | 20 | # Alias MONGO variables 21 | if [ -z "$DB_URI" ]; then 22 | export MONGO_HOST="${MONGO_PORT_27017_TCP_ADDR:-localhost}" 23 | export MONGO_PORT="${MONGO_PORT_27017_TCP_PORT:-27017}" 24 | echo "$(basename $0) >> Set MONGO_HOST=$MONGO_HOST, MONGO_PORT=$MONGO_PORT" 25 | fi 26 | 27 | # Check that SMTP variables are defined 28 | if [ -z "${SMTP_PORT_587_TCP_ADDR}" -a -z "$SMTP_HOST" ]; then 29 | echo "You must link this container with SMTP or define SMTP_HOST" 30 | exit 1 31 | fi 32 | 33 | # Alias SMTP variables 34 | if [ -z "$SMTP_HOST" ]; then 35 | export SMTP_HOST="${SMTP_PORT_587_TCP_ADDR:-localhost}" 36 | export SMTP_PORT="${SMTP_PORT_587_TCP_PORT:-587}" 37 | echo "$(basename $0) >> Set SMTP_HOST=$SMTP_HOST, SMTP_PORT=$SMTP_PORT" 38 | fi 39 | 40 | # Wait for SMTP to be available 41 | while ! exec 6<>/dev/tcp/${SMTP_HOST}/${SMTP_PORT}; do 42 | echo "$(date) - waiting to connect to SMTP at ${SMTP_HOST}:${SMTP_PORT}" 43 | sleep 1 44 | done 45 | 46 | exec 6>&- 47 | exec 6<&- 48 | 49 | # Create a DB_URI from linked container. See variables above. 50 | if [ -z "$DB_URI" ]; then 51 | export DB_URI="mongodb://${MONGO_HOST:-${MONGO_PORT_27017_TCP_ADDR:-localhost}}:${MONGO_PORT:-${MONGO_PORT_27017_TCP_PORT:-27017}}/strider" 52 | echo 'export DB_URI="mongodb://${MONGO_HOST:-${MONGO_PORT_27017_TCP_ADDR:-localhost}}:${MONGO_PORT:-${MONGO_PORT_27017_TCP_PORT:-27017}}/strider"' > $HOME/.bashrc 53 | echo "$(basename $0) >> Set DB_URI=$DB_URI" 54 | fi 55 | 56 | # Extract port / host for testing below 57 | MONGO_PORT=$(python -c "from urlparse import urlparse; print urlparse('$DB_URI').port") 58 | MONGO_HOST=$(python -c "from urlparse import urlparse; print urlparse('$DB_URI').hostname") 59 | 60 | # Wait for Mongo to be available 61 | while ! exec 6<>/dev/tcp/${MONGO_HOST}/${MONGO_PORT}; do 62 | echo "$(date) - waiting to connect to MONGO at ${MONGO_HOST}:${MONGO_PORT}" 63 | sleep 1 64 | done 65 | 66 | exec 6>&- 67 | exec 6<&- 68 | 69 | # Update npm cache if no modules exist 70 | if [ ! -d "${STRIDER_HOME}/node_modules" ]; then 71 | echo "$(basename $0) >> Copying node_modules from cache..." 72 | mkdir -p ${STRIDER_HOME}/node_modules 73 | cp -r --preserve=mode,timestamps,links,xattr ${STRIDER_SRC}/node_modules.cache/* ${STRIDER_HOME}/node_modules/ 74 | fi 75 | 76 | # Create admin user if variables defined 77 | if [ ! -z "$STRIDER_ADMIN_EMAIL" -a ! -z "$STRIDER_ADMIN_PASSWORD" ]; then 78 | echo "$(basename $0) >> Running addUser" 79 | strider addUser --email $STRIDER_ADMIN_EMAIL --password $STRIDER_ADMIN_PASSWORD --force --admin true 80 | echo "$(basename $0) >> Created Admin User: $STRIDER_ADMIN_EMAIL, Password: $STRIDER_ADMIN_PASSWORD" 81 | fi 82 | 83 | echo "Exec'ing command $@" 84 | exec "$@" 85 | -------------------------------------------------------------------------------- /run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | [ "$DEBUG" == 'true' ] && set -x 6 | 7 | # 8 | # Config 9 | # 10 | 11 | TEST_IMAGE='strider' 12 | TEST_PORT=3000 13 | 14 | # 15 | # Functions 16 | # 17 | 18 | function rm_container { 19 | set +e 20 | docker rm -fv "$@" > /dev/null 2>&1 21 | set -e 22 | } 23 | 24 | function cleanup { 25 | echo "=> Clean up" 26 | rm_container $TEST_IMAGE mongo smtp 27 | } 28 | 29 | function wait_on_http { 30 | TIMEOUT=$1 31 | shift 32 | for (( i=0;; i++ )); do 33 | if [ ${i} -eq ${TIMEOUT} ]; then 34 | break 35 | fi 36 | sleep 1 37 | curl --insecure --location "$@" > /dev/null 2>&1 && break 38 | done 39 | } 40 | 41 | function start_docker { 42 | echo "=> Starting docker" 43 | if ! docker version > /dev/null 2>&1; then 44 | wrapdocker > /dev/null 2>&1 & 45 | sleep 5 46 | fi 47 | } 48 | 49 | function check_docker { 50 | echo "=> Checking docker daemon" 51 | docker version > /dev/null 2>&1 || (echo "Failed to start docker (did you use --privileged when running this container?)" && exit 1) 52 | } 53 | 54 | function check_environment { 55 | echo "=> Testing environment" 56 | docker version 57 | which curl > /dev/null 58 | } 59 | 60 | function build_image { 61 | echo "=> Building $TEST_IMAGE image" 62 | docker build -t $TEST_IMAGE . 63 | } 64 | 65 | function run_tests { 66 | echo "==> Running tests" 67 | echo "=> Test running" 68 | docker run -d --name mongo mongo:latest 69 | docker run -d --name smtp -e MAILNAME=test panubo/postfix:latest 70 | docker run -d --name $TEST_IMAGE -p $TEST_PORT:$TEST_PORT --link mongo --link smtp $TEST_IMAGE 71 | echo "=> Test container is up" 72 | wait_on_http 30 localhost:3000 73 | curl -s localhost:$TEST_PORT | grep 'Strider: Brilliant Continuous Deployment' > /dev/null 74 | } 75 | 76 | # 77 | # Begin main 78 | # 79 | 80 | echo "=> Starting $0" 81 | start_docker 82 | check_docker 83 | check_environment 84 | cleanup 85 | build_image 86 | run_tests 87 | cleanup 88 | echo "=> Done!" -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | [ "$DEBUG" == 'true' ] && set -x 6 | 7 | TEST_CONTAINER='strider-test' 8 | DOCKERFILE="Dockerfile.test" 9 | 10 | echo ">> Using Temp Dockerfile: $DOCKERFILE" 11 | 12 | cat << EOF > $DOCKERFILE 13 | FROM jpetazzo/dind:latest 14 | ADD * /build/ 15 | WORKDIR /build 16 | CMD ["/build/run-tests.sh"] 17 | EOF 18 | 19 | echo ">> Building" 20 | docker build -f $DOCKERFILE -t $TEST_CONTAINER . 21 | 22 | echo ">> Running" 23 | docker run --privileged -ti --rm $TEST_CONTAINER 24 | 25 | echo ">> Removing" 26 | docker rmi $TEST_CONTAINER --------------------------------------------------------------------------------