Skip to content

Commit

Permalink
Image revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
csandanov committed Feb 8, 2018
1 parent e23d70a commit a97ca7f
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 92 deletions.
36 changes: 22 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
language: python

sudo: required
language: bash

services:
- docker

env:
global:
- LATEST_VERSION=2.3
- LATEST_TAG=2.3
matrix:
- VERSION=2.3
- TAG=2.3 CACHET_VER=2.3.13 EXTRA_TAG=2

script:
- cd ./$VERSION
- make && make test
- travis_retry make && make test

after_success: |
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && ([ "$TRAVIS_BRANCH" == "master" ] || [ -n "$TRAVIS_TAG" ]); then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
make release
if [[ "${TRAVIS_PULL_REQUEST}" == "false" && ("${TRAVIS_BRANCH}" == "master" || -n "${TRAVIS_TAG}") ]]; then
docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}"
if [ -n "$TRAVIS_TAG" ]; then
make VERSION="$VERSION-$TRAVIS_TAG" release
if [[ -n "${TRAVIS_TAG}" ]]; then
export STABILITY_TAG="${TRAVIS_TAG}"
fi
if [ "$VERSION" == "$LATEST_VERSION" ]; then
make VERSION=latest release
if [[ -n "${EXTRA_TAG}" ]]; then
make release TAG="${EXTRA_TAG}"
fi
make release
if [[ "${TAG}" == "${LATEST_TAG}" ]]; then
make release TAG="latest"
fi
fi
notifications:
on_failure: never
slack:
secure: |
sytMKHWYfSPPEPK+56nGsjoNa2qALaIRVk08kzh2ik6DEj3dQfeEdhIrK5fXLi2zT/x7DIa7XEWbYEkozSmgAQiw9R/gK8G0dEsJF3XvgazxARAVObgM2ehcW0h/Jkm7wr3NytFTp8frdBjp2EiMu9C+IvtYKkAqtvFWSK2FKIbtreJTED9Mn5SFkpLcw1V32Jl08Lsnco8gOSMk7y5hxZ5K1aRVQtEt4Vo1TT36EAO6iUiIGy1xaRGr5TEmcL+U9BeqsEM08TCejeDlEh7Oy/58JSyM4OFi5/LiA93oDrycX2XvsxbPLHfb0leEWYJ0mpWv2jNAm+SU915di6ibdg6t0qAc+5VbsXijZlbufrkVMr7k9BPTXUiZcUiBjDQSqUeEXJJyPAtuuNYfQ0AWbRH4Y+6nu6st0aRHaFo5ng7eohLGiDQpsX59Kw+xn4OyBzeISJwCFYI8auVhzOAtP09S45P47BBLuTDoIlBf0Lx3wvFNsjSVsotQLqcg0s8NusfX2vZRMNVReUtwicjAyYWY3cyCPLWww8F16g5IEpslCqRZP0a6ge+R34I36DkiURb8yuoUDndAL3A+OZi0Rd4tYccrU+DlaqAb7tpUCRO4iGcKogwA6/nVbSPH5rSKyTf9NKYmtD4Y511vqWtVKbDYOGY1vF0xGNyxMV5RaI4=
15 changes: 0 additions & 15 deletions 2.3/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions 2.3/actions/actions.mk

This file was deleted.

10 changes: 0 additions & 10 deletions 2.3/init/20-cachet.sh

This file was deleted.

26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM wodby/php:7.1-3.6.1

ARG CACHET_VER

ENV APP_NAME="Cachet" \
CACHET_VER="${CACHET_VER}"

USER root

RUN set -ex; \
\
mkdir -p /usr/src/cachet; \
wget -qO- "https://github.com/CachetHQ/Cachet/archive/v${CACHET_VER}.tar.gz" \
| tar xz --strip-components=1 -C /usr/src/cachet; \
chown -R www-data:www-data /usr/src/cachet; \
\
mv /usr/local/bin/actions.mk /usr/local/bin/php.mk; \
\
su-exec www-data composer install -d /usr/src/cachet --no-dev -o; \
su-exec www-data composer clear-cache

USER www-data

COPY templates /etc/gotpl/
COPY actions /usr/local/bin/
COPY init /docker-entrypoint-init.d/
30 changes: 18 additions & 12 deletions 2.3/Makefile → Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
-include env_make

VERSION ?= 2.3
CACHET_VER ?= 2.3.13
TAG ?= $(CACHET_VER)

REPO = wodby/cachet
NAME = cachet-$(VERSION)
NAME = cachet-$(CACHET_VER)

ifneq ($(STABILITY_TAG),)
ifneq ($(TAG),latest)
override TAG := $(TAG)-$(STABILITY_TAG)
endif
endif

.PHONY: build test push shell run start stop logs clean release

default: build

build:
docker build -t $(REPO):$(VERSION) ./
docker build -t $(REPO):$(TAG) --build-arg CACHET_VER=$(CACHET_VER) ./

test:
cd ./test/ && IMAGE=$(REPO):$(VERSION) ./test.sh
cd ./test && IMAGE=$(REPO):$(TAG) ./test.sh

push:
docker push $(REPO):$(VERSION)
docker push $(REPO):$(TAG)

shell:
docker run --rm --name $(NAME) -i -t $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(VERSION) /bin/bash
docker run --rm --name $(NAME) -i -t $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) /bin/bash

run:
docker run --rm --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(VERSION) $(CMD)
docker run --rm --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) $(CMD)

start:
docker run -d --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(VERSION)
docker run -d --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG)

stop:
docker stop $(NAME)
Expand All @@ -34,7 +43,4 @@ logs:
clean:
-docker rm -f $(NAME)

release: build
make push -e VERSION=$(VERSION)

default: build
release: build push
72 changes: 65 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,76 @@
# PHP docker container image with Cachet inside
# Cachet Docker Container Image

[![Build Status](https://travis-ci.org/wodby/cachet.svg?branch=master)](https://travis-ci.org/wodby/cachet)
[![Docker Pulls](https://img.shields.io/docker/pulls/wodby/cachet.svg)](https://hub.docker.com/r/wodby/cachet)
[![Docker Stars](https://img.shields.io/docker/stars/wodby/cachet.svg)](https://hub.docker.com/r/wodby/cachet)
[![Wodby Slack](http://slack.wodby.com/badge.svg)](http://slack.wodby.com)
[![Docker Layers](https://images.microbadger.com/badges/image/wodby/cachet.svg)](https://microbadger.com/images/wodby/cachet)

## Supported tags and respective `Dockerfile` links
## Docker Images

- [`2.3`, (*2.3/Dockerfile*)](https://github.com/wodby/cachet/tree/master/2.3/Dockerfile)
!!! For better reliability we release images with stability tags (`wodby/cachet:2.3-X.X.X`) which correspond to [git tags](https://github.com/wodby/cachet/releases). We **STRONGLY RECOMMEND** using images only with stability tags.

## Environment variables available for customization
Overview:

See at [wodby/php](https://github.com/wodby/php)
* All images are based on Alpine Linux
* Base image: [wodby/php](https://github.com/wodby/php)
* [TravisCI builds](https://travis-ci.org/wodby/cachet)
* [Docker Hub](https://hub.docker.com/r/wodby/cachet)

## Using in production
Supported tags and respective `Dockerfile` links:

* `2`, `2.3`, `latest` [_(Dockerfile)_](https://github.com/wodby/cachet/tree/master/Dockerfile)

## Environment Variables

| Variable | Default Value | Description |
| ----------------------- | ------------------ | ----------- |
| `CACHET_APP_ENV` | `development` | |
| `CACHET_APP_DEBUG` | `false` | |
| `CACHET_APP_URL` | `http://localhost` | |
| `CACHET_DB_DRIVER` | `pgsql` | |
| `CACHET_DB_HOST` | | |
| `CACHET_DB_UNIX_SOCKET` | `null` | |
| `CACHET_DB_DATABASE` | | |
| `CACHET_DB_USERNAME` | | |
| `CACHET_DB_PASSWORD` | | |
| `CACHET_DB_PORT` | `5432` | |
| `CACHET_DB_PREFIX` | | |
| `CACHET_CACHE_DRIVER` | `apc` | |
| `CACHET_SESSION_DRIVER` | `apc` | |
| `CACHET_QUEUE_DRIVER` | `database` | |
| `CACHET_BEACON` | `true` | |
| `CACHET_EMOJI` | `false` | |
| `CACHET_AUTO_TWITTER` | `true` | |
| `CACHET_MAIL_DRIVER` | `smtp` | |
| `CACHET_MAIL_HOST` | `localhost` | |
| `CACHET_MAIL_PORT` | `25` | |
| `CACHET_MAIL_USERNAME` | `null` | |
| `CACHET_MAIL_PASSWORD` | `null` | |
| `CACHET_MAIL_ADDRESS` | `null` | |
| `CACHET_MAIL_NAME` | `null` | |
| `CACHET_MAIL_ENCRYPTION` | `null` | |
| `CACHET_REDIS_HOST` | `null` | |
| `CACHET_REDIS_DATABASE` | `cachet` | |
| `CACHET_REDIS_PORT` | `6379` | |
| `CACHET_GITHUB_TOKEN` | `null` | |
| `CACHET_NEXMO_KEY` | `null` | |
| `CACHET_NEXMO_SECRET` | `null` | |
| `CACHET_NEXMO_SMS_FROM` | `Cachet` | |

See [wodby/php](https://github.com/wodby/php) for all variables

## Orchestration Actions

Usage:
```
make COMMAND [params ...]
commands:
init
```

See [wodby/php](https://github.com/wodby/php) for all actions

## Deployment

Deploy Cachet to your own server via [![Wodby](https://www.google.com/s2/favicons?domain=wodby.com) Wodby](https://wodby.com).
8 changes: 8 additions & 0 deletions actions/actions.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-include /usr/local/bin/php.mk

.PHONY: init

default: init

init:
init.sh
30 changes: 15 additions & 15 deletions 2.3/actions/init.sh → actions/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pass="${CACHET_DB_PASSWORD}"
db="${CACHET_DB_DATABASE}"
prefix="${CACHET_DB_PREFIX}"

checkDBConnection() {
check_db_connection() {
echo "Checking database connection..."
case "${CACHET_DB_DRIVER:=pgsql}" in
mysql)
Expand Down Expand Up @@ -44,60 +44,60 @@ checkDBConnection() {
echo 'DBMS has started!'
}

checkDBInit() {
check_db_init() {
case "${CACHET_DB_DRIVER}" in
mysql)
checkDBInitMySQL
check_db_init_mysql
;;
pgsql)
checkDBInitPostgres
check_db_init_postgres
;;
esac
}

checkDBInitMySQL() {
check_db_init_mysql() {
table=sessions
if [[ "$(mysql -N -s -h "${host}" -u "${user}" "${pass}" "${db}" -e \
"select count(*) from information_schema.tables where \
table_schema='${db}' and table_name='${prefix}${table}';")" -eq 1 ]]; then
echo "DB is already initialized..."
else
InitDB
init_db
fi
}

checkDBInitPostgres() {
check_db_init_postgres() {
table=sessions
if [[ "$(PGPASSWORD="${pass}" psql -h "${host}" -U "${user}" -d "${db}" \
-c "SELECT to_regclass('${prefix}${table}');" | grep -c "${prefix}${table}")" -eq 1 ]]; then
echo "DB is already initialized..."
else
InitDB
init_db
fi
}

InitDB() {
init_db() {
echo "Initializing Cachet database ..."
php artisan app:install
php artisan config:cache
}

copyCachet() {
if ! [ -e "${APP_ROOT}/server.php" ]; then
copy_cachet() {
if [[ ! -f "${APP_ROOT}/server.php" ]]; then
echo >&2 "Cachet not found in ${APP_ROOT} - copying now..."
rsync -rlt "/usr/src/cachet/" "${APP_ROOT}/"
rsync -rplt "/usr/src/cachet/" "${APP_ROOT}/"
echo >&2 "Complete! Cachet has been successfully copied to ${APP_ROOT}"
rm -rf bootstrap/cache/*
chmod -R 777 storage
fi
}

copyCachet
copy_cachet

if [[ -n "${host}" ]]; then
gotpl "/etc/gotpl/env.tpl" > "${APP_ROOT}/.env"
checkDBConnection
checkDBInit
check_db_connection
check_db_init
touch /home/www-data/.initialized
else
echo "DB credentials missing, omit initialization."
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions init/20-cachet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

if [[ -n "${DEBUG}" ]]; then
set -x
fi

# Automatically trigger init action when running outside Wodby.
if [[ -z "${WODBY_APP_NAME}" ]]; then
make init -f /usr/local/bin/actions.mk
fi
File renamed without changes.
3 changes: 2 additions & 1 deletion 2.3/test/docker-compose.yml → test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ version: "2"

services:
nginx:
image: wodby/cachet-nginx:2.3-1.13
image: wodby/php-nginx
environment:
NGINX_BACKEND_HOST: cachet
NGINX_SERVER_ROOT: /var/www/html/public
volumes:
- codebase:/var/www/html
ports:
Expand Down
File renamed without changes.

0 comments on commit a97ca7f

Please sign in to comment.