Skip to content

Commit

Permalink
Merge pull request #23 from docksal/develop
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
lmakarov authored Jul 2, 2020
2 parents c807e7c + 699a711 commit cc345cd
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 60 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
dist: xenial
dist: bionic

language: minimal

env:
global:
- REPO=docksal/mysql
- LATEST_VERSION=8.0

matrix:
- VERSION=5.6 FROM=mysql:5.6 TAGS=5.6,latest
- VERSION=5.7 FROM=mysql:5.7 TAGS=5.7
- VERSION=8.0 FROM=mysql:8.0 TAGS=8.0
- VERSION=5.6 FROM=mysql:5.6
- VERSION=5.7 FROM=mysql:5.7
- VERSION=8.0 FROM=mysql:8.0

install:
# Install Docksal to have a matching versions of Docker on the build host
Expand All @@ -22,7 +23,7 @@ script:
- make test

after_success:
- ${TRAVIS_BUILD_DIR}/release.sh
- make release

after_failure:
- make logs
5 changes: 5 additions & 0 deletions 8.0/default.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ innodb_log_file_size = 128MB

innodb_file_per_table = 1

# Use the older (pre 8.0.4) authentication method for (backward) compatibility between MySQL/MariaDB
# See https://mariadb.com/kb/en/authentication-plugin-sha-256/
# See https://stackoverflow.com/questions/49963383/authentication-plugin-caching-sha2-password
default_authentication_plugin = mysql_native_password

# Max packets
max_allowed_packet = 128M
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ VOLUME /var/lib/mysql
COPY docker-entrypoint.d /docker-entrypoint.d
COPY healthcheck.sh /opt/healthcheck.sh

COPY docker-entrypoint.patch /usr/local/bin/docker-entrypoint.patch
COPY docker-preinit-entrypoint.patch /usr/local/bin/docker-preinit-entrypoint.patch
COPY docker-postinit-entrypoint.patch /usr/local/bin/docker-postinit-entrypoint.patch

# Apply patch for running scripts placed in /docker-entrypoint.d/* by root
RUN set -xe; \
sed -i '/\$(id -u)/ r /usr/local/bin/docker-entrypoint.patch' /usr/local/bin/docker-entrypoint.sh; \
rm -f /usr/local/bin/docker-entrypoint.patch
sed -i -e '/Switching to dedicated user/r /usr/local/bin/docker-preinit-entrypoint.patch' /usr/local/bin/docker-entrypoint.sh; \
sed -n -i -e '/docker_process_init_files \/docker-entrypoint-initdb.d\/\*/ r /usr/local/bin/docker-postinit-entrypoint.patch' -e 1x -e '2,${x;p}' -e '${x;p}' /usr/local/bin/docker-entrypoint.sh; \
rm -f /usr/local/bin/docker-preinit-entrypoint.patch /usr/local/bin/docker-postinit-entrypoint.patch

EXPOSE 3306
CMD ["mysqld"]
Expand Down
30 changes: 14 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

FROM ?= mysql:5.6
VERSION ?= 5.6
TAG ?= $(VERSION)
REPO ?= docksal/mysql
BUILD_TAG ?= $(VERSION)
SOFTWARE_VERSION ?= $(VERSION)

REPO ?= docksal/mysql
NAME = docksal-mysql-$(VERSION)

MYSQL_ROOT_PASSWORD = root
Expand All @@ -14,31 +15,27 @@ 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) -e VERSION=$(VERSION)

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

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

build:
docker build -t $(REPO):$(TAG) --build-arg FROM=$(FROM) --build-arg VERSION=$(VERSION) .
docker build -t $(REPO):$(BUILD_TAG) --build-arg FROM=$(FROM) --build-arg VERSION=$(VERSION) .

test:
IMAGE=$(REPO):$(TAG) NAME=$(NAME) VERSION=$(VERSION) bats ./tests/test.bats
IMAGE=$(REPO):$(BUILD_TAG) NAME=$(NAME) VERSION=$(VERSION) ./tests/test.bats

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

shell:
docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) /bin/bash
shell: clean
docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(BUILD_TAG) /bin/bash

run:
docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG)
run: clean
docker run --rm --name $(NAME) -it $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(BUILD_TAG)

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

exec:
docker exec $(NAME) /bin/bash -c "$(CMD)"
Expand All @@ -56,6 +53,7 @@ logs:
clean:
docker rm -f $(NAME) >/dev/null 2>&1 || true

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

default: build
7 changes: 0 additions & 7 deletions docker-entrypoint.patch

This file was deleted.

1 change: 1 addition & 0 deletions docker-postinit-entrypoint.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker_process_init_files /var/www/.docksal/services/db/*
7 changes: 7 additions & 0 deletions docker-preinit-entrypoint.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Process pre init scripts run by root
for f in /docker-entrypoint.d/*.sh; do
echo "Running init scripts in /docker-entrypoint.d/ as root..."
. "$f"
done

28 changes: 0 additions & 28 deletions release.sh

This file was deleted.

87 changes: 87 additions & 0 deletions scripts/docker-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash

# ----- Helper functions ----- #

is_edge ()
{
[[ "${TRAVIS_BRANCH}" == "develop" ]]
}

is_stable ()
{
[[ "${TRAVIS_BRANCH}" == "master" ]]
}

is_release ()
{
[[ "${TRAVIS_TAG}" != "" ]]
}

# Check whether the current build is for a pull request
is_pr ()
{
[[ "${TRAVIS_PULL_REQUEST}" != "false" ]]
}

is_latest ()
{
[[ "${VERSION}" == "${LATEST_VERSION}" ]]
}

# Tag and push an image
# $1 - source image
# $2 - target image
tag_and_push ()
{
local source=$1
local target=$2

# Base image
echo "Pushing ${target} image ..."
docker tag ${source} ${target}
docker push ${target}
}

# ---------------------------- #

# Extract version parts from release tag
IFS='.' read -a ver_arr <<< "$TRAVIS_TAG"
VERSION_MAJOR=${ver_arr[0]#v*} # 2.7.0 => "2"
VERSION_MINOR=${ver_arr[1]} # "2.7.0" => "7"

# Set tags if exists
SOFTWARE_VERSION="${SOFTWARE_VERSION:+${SOFTWARE_VERSION}-}"

# Possible docker image tags
# "image:tag" pattern: <image-repo>:<software-version>[-<image-stability-tag>][-<flavor>]
IMAGE_TAG_EDGE="${SOFTWARE_VERSION}edge" # e.g., [SOFTWARE_VERSION-]edge
IMAGE_TAG_STABLE="${SOFTWARE_VERSION}stable" # e.g., [SOFTWARE_VERSION-]stable
IMAGE_TAG_RELEASE_MAJOR="${SOFTWARE_VERSION}${VERSION_MAJOR}" # e.g., [SOFTWARE_VERSION-]2
IMAGE_TAG_RELEASE_MAJOR_MINOR="${SOFTWARE_VERSION}${VERSION_MAJOR}.${VERSION_MINOR}" # e.g., [SOFTWARE_VERSION-]2.7
IMAGE_TAG_LATEST="latest"

# Skip pull request builds
is_pr && exit

docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"

# Push images
if is_edge; then
tag_and_push ${REPO}:${BUILD_TAG} ${REPO}:${IMAGE_TAG_EDGE}
elif is_stable; then
tag_and_push ${REPO}:${BUILD_TAG} ${REPO}:${IMAGE_TAG_STABLE}
elif is_release; then
# Have stable, major, minor tags match
tag_and_push ${REPO}:${BUILD_TAG} ${REPO}:${IMAGE_TAG_STABLE}
tag_and_push ${REPO}:${BUILD_TAG} ${REPO}:${IMAGE_TAG_RELEASE_MAJOR}
tag_and_push ${REPO}:${BUILD_TAG} ${REPO}:${IMAGE_TAG_RELEASE_MAJOR_MINOR}
else
# Exit if not on develop, master or release tag
exit
fi

# Special case for the "latest" tag
# Push (base image only) on stable and release builds
if is_latest && (is_stable || is_release); then
tag_and_push ${REPO}:${BUILD_TAG} ${REPO}:${IMAGE_TAG_LATEST}
fi
4 changes: 3 additions & 1 deletion tests/test.bats
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ _healthcheck_wait ()

### Setup ###
make start -e VOLUMES="-v $(pwd)/tests:/var/www"
_healthcheck_wait

run _healthcheck_wait
unset output

### Tests ###
# MySQL does a restart, so there should be two of these in the logs after a successful start
Expand Down

0 comments on commit cc345cd

Please sign in to comment.