Skip to content

Commit

Permalink
Merge pull request #13 from docksal/develop
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
lmakarov authored Nov 22, 2018
2 parents 5416825 + 1b43691 commit 003d461
Show file tree
Hide file tree
Showing 25 changed files with 340 additions and 1,031 deletions.
31 changes: 9 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
sudo: required

language: generic

services:
- docker

env:
global:
- REPO=docksal/db
- DOCKSAL_VERSION=develop
- LATEST_VERSION=mysql-5.6
matrix:
- VERSION=mysql-5.5
Expand All @@ -14,33 +16,18 @@ env:
- VERSION=mysql-8.0

install:
- curl -fsSL get.docksal.io | bash
# Install Docksal to have a matching versions of Docker on the build host
- curl -fsSL https://get.docksal.io | bash
- fin version
- fin sysinfo

script:
- cd ${VERSION}
- make && make test

after_success: |
if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then
[[ "${TRAVIS_BRANCH}" == "develop" ]] && TAG="edge-${VERSION}"
[[ "${TRAVIS_BRANCH}" == "master" ]] && TAG="${VERSION}"
[[ "${TRAVIS_TAG}" != "" ]] && TAG="${TRAVIS_TAG:1:3}-${VERSION}"
if [[ "$TAG" != "" ]]; then
docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"
# Push edge, stable and release tags
docker tag ${REPO}:${VERSION} ${REPO}:${TAG}
docker push ${REPO}:${TAG}
- make
- make test

# Push "latest" tag
if [[ "${TRAVIS_BRANCH}" == "master" ]] && [[ "${VERSION}" == "${LATEST_VERSION}" ]]; then
docker tag ${REPO}:${VERSION} ${REPO}:latest
docker push ${REPO}:latest
fi
fi
fi
after_success:
- make release

after_failure:
- make logs
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Database Docker images for Docksal

Docksal MySQL images are derived from the stock `mysql` images from Docker Hub.
We include extra settings (see `default.cnf`) and make slight modifications to `docker-entrypoint.sh`.
Docksal MySQL images are derived from the stock `mysql` images from Docker Hub with a few adjustments (see Features).

We include and enable user defined overrides via a settings file.

This image(s) is part of the [Docksal](http://docksal.io) image library.

## Features

- Better default settings (see `default.cnf`)
- Ability to pass additional settings via a file mounted into the container
- User defined MySQL settings are expected in `/var/www/.docksal/etc/mysql/my.cnf` in the container.
- Running a startup script as root
- Scripts should be placed in the `/docker-entrypoint.d/` folder
- Docker heathcheck support

## Versions

- `mysql-5.5`
- `mysql-5.6`
- `mysql-5.7`, `latest`
- `mysql-5.6`, `latest`
- `mysql-5.7`
- `mysql-8.0`
18 changes: 10 additions & 8 deletions mysql-5.5/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM mysql:5.5.61

# Docksal settings
# MySQL settings
COPY default.cnf /etc/mysql/conf.d/10-default.cnf

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /entrypoint.sh
# Add support for init script run under root user at startup
# Scripts should be placed in the /docker-entrypoint.d/ folder
COPY docker-entrypoint.d.sh /usr/local/bin/docker-entrypoint.d.sh
RUN set -xe; \
sed -i '/\$(id -u)/ r /usr/local/bin/docker-entrypoint.d.sh' /usr/local/bin/docker-entrypoint.sh
# Init scripts run under root
COPY docker-entrypoint.d /docker-entrypoint.d
COPY healthcheck.sh /opt/healthcheck.sh

ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 3306
CMD ["mysqld"]
# Fix PATH to include MySQL 5.5 binaries
RUN echo 'PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts' >> /etc/profile

# Health check script
HEALTHCHECK --interval=5s --timeout=1s --retries=12 CMD ["/opt/healthcheck.sh"]
49 changes: 30 additions & 19 deletions mysql-5.5/Makefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
-include env_make

SHELL = /bin/bash
VERSION ?= mysql-5.5

REPO = docksal/db
NAME = docksal-db-$(VERSION)
IMAGE = $(REPO):$(VERSION)
NAME = docksal-db-${VERSION}
MYSQL_ROOT_PASSWORD = root
MYSQL_USER = user
MYSQL_PASSWORD = user
MYSQL_DATABASE = default
ENV = -e MYSQL_ROOT_PASSWORD=$(MYSQL_ROOT_PASSWORD) -e MYSQL_USER=$(MYSQL_USER) -e MYSQL_PASSWORD=$(MYSQL_PASSWORD) -e MYSQL_DATABASE=$(MYSQL_DATABASE)
ENV = -e MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} -e MYSQL_USER=${MYSQL_USER} -e MYSQL_PASSWORD=${MYSQL_PASSWORD} -e MYSQL_DATABASE=${MYSQL_DATABASE}

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

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

build:
docker build -t $(IMAGE) .
fin docker build -t ${REPO}:${VERSION} .

test:
IMAGE=$(IMAGE) NAME=$(NAME) bats ../tests/test.bats
IMAGE=${REPO}:${VERSION} bats ../tests/test.bats

push:
docker push $(IMAGE)
fin docker push ${REPO}:${VERSION}

exec:
@fin docker exec ${NAME} ${CMD}

exec-it:
@fin docker exec -it ${NAME} ${CMD}

shell:
docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) $(IMAGE) /bin/bash
@make exec-it -e CMD=sh

run:
docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) $(IMAGE)
fin docker run --rm --name ${NAME} -it ${PORTS} ${VOLUMES} ${ENV} ${REPO}:${VERSION}

start: clean
docker run -d --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(IMAGE)

exec:
docker exec -it $(NAME) /bin/bash
fin docker run -d --name ${NAME} ${PORTS} ${VOLUMES} ${ENV} ${REPO}:${VERSION}

mysql-query:
# Usage: make mysql-query QUERY='SHOW DATABASES;'
docker exec $(NAME) bash -c "mysql --host=localhost --user=root --password=$(MYSQL_ROOT_PASSWORD) -e '$(QUERY)'"
fin docker exec ${NAME} bash -c "mysql --host=localhost --user=root --password=${MYSQL_ROOT_PASSWORD} -e '${QUERY}'"

stop:
docker stop $(NAME)
fin docker stop ${NAME}

logs:
docker logs $(NAME)
fin docker logs ${NAME}

clean:
docker rm -f $(NAME) >/dev/null 2>&1 || true
logs-follow:
fin docker logs -f ${NAME}

debug: build start logs-follow

release: build push
release:
@../scripts/release.sh

clean:
fin docker rm -vf ${NAME} || true

default: build
7 changes: 7 additions & 0 deletions mysql-5.5/docker-entrypoint.d.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Process init scripts run by root
for f in /docker-entrypoint.d/*; do
echo "Running init scripts in /docker-entrypoint.d/ as root..."
process_init_file "$f" "${mysql[@]}"
done

12 changes: 12 additions & 0 deletions mysql-5.5/docker-entrypoint.d/10-custom-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

if [[ "$(id -u)" = '0' ]]; then
# Copy custom settings (if mounted) from /var/www/.docksal/etc/mysql/my.cnf and fix permissions
project_config_file='/var/www/.docksal/etc/mysql/my.cnf'
echo "Including custom configuration from ${project_config_file}"
if [[ -f ${project_config_file} ]]; then
cp -a ${project_config_file} /etc/mysql/conf.d/99-overrides.cnf
chown -R root:root /etc/mysql/conf.d/*
chmod -R 644 /etc/mysql/conf.d/*
fi
fi
Loading

0 comments on commit 003d461

Please sign in to comment.