Skip to content

Commit

Permalink
Initial, sort of over engineered version (#1)
Browse files Browse the repository at this point in the history
* fix tests, use table as a pool <eugh>

* fix tests and linting

* sort files by largest first

* support schema:tables input;

* make the schema directory if it does not exist

* update parallel-process

* update Dockerfile to latest

* remove mkdir section, todo: add injected filesystem

* allow older yaml versions

* update composer version, some fixes
  • Loading branch information
Harry Bragg authored Aug 9, 2018
1 parent f010fe5 commit c7642c3
Show file tree
Hide file tree
Showing 49 changed files with 2,176 additions and 1,161 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ language: php

dist: trusty

## Cache composer bits
cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.6
- 7.0
- 7.1
- hhvm
- 7.2
- nightly

env:
Expand All @@ -22,6 +22,7 @@ matrix:
- php: nightly

before_script:
- composer config platform.php $(php -r "echo PHP_VERSION;")
- travis_retry composer update --no-interaction --prefer-dist $PREFER_LOWEST

script:
Expand Down
31 changes: 27 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
FROM php:7.1-alpine
FROM composer AS build

WORKDIR /app
COPY src /app/src
COPY composer.json /app/composer.json
COPY composer.lock /app/composer.lock

RUN composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader --prefer-dist

FROM graze/php-alpine:7.2 AS run

RUN set +xe \
&& apk add --no-cache \
mariadb-client

WORKDIR /app
COPY --from=build /app/src /app/src
COPY --from=build /app/vendor /app/vendor
COPY bin /app/bin
COPY src /app/src
COPY vendor /app/vendor

VOLUME ["/seed", "/app/config"]
ARG BUILD_DATE
ARG VCS_REF

LABEL org.label-schema.schema-version="1.0" \
org.label-schema.vendor="graze" \
org.label-schema.name="morphism" \
org.label-schema.description="seed your databases" \
org.label-schema.vcs-url="https://github.com/graze/sprout" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.build-date=$BUILD_DATE \
maintainer="developers@graze.com" \
license="MIT"

VOLUME ["/app/config", "/seed"]

ENTRYPOINT ["php", "/app/bin/sprout"]
CMD ["list"]
51 changes: 31 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
SHELL = /bin/sh

DOCKER ?= $(shell which docker)
DOCKER = $(shell which docker)
PHP_VER := 7.2
IMAGE := graze/php-alpine:${PHP_VER}-test
VOLUME := /srv
IMAGE ?= graze/php-alpine:test
DOCKER_RUN := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME} ${IMAGE}
DOCKER_RUN_BASE := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME}
DOCKER_RUN := ${DOCKER_RUN_BASE} ${IMAGE}

PREFER_LOWEST ?=

.PHONY: build build-update composer-% clean help run
.PHONY: lint lint-fix
.PHONY: test test-unit test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover
.PHONY: test test-unit test-integration test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover

.SILENT: help

# Building

build: ## Download the dependencies then build the image :rocket:.
make 'composer-install --prefer-dist --optimize-autoloader'
build: ## Install the dependencies
build: ensure-composer-file
make 'composer-install --optimize-autoloader --prefer-dist ${PREFER_LOWEST}'

build-update: ## Update all dependencies
make 'composer-update --prefer-dist --optimize-autoloader ${PREFER_LOWEST}'
build-update: ## Update the dependencies
build-update: ensure-composer-file
make 'composer-update --optimize-autoloader --prefer-dist ${PREFER_LOWEST}'

ensure-composer-file: # Update the composer file
make 'composer-config platform.php ${PHP_VER}'

composer-%: ## Run a composer command, `make "composer-<command> [...]"`.
${DOCKER} run -t --rm \
-v $$(pwd):/app \
-v ~/.composer:/tmp \
-v $$(pwd):/app:delegated \
-v ~/.composer:/tmp:delegated \
-v ~/.ssh:/root/.ssh:ro \
composer --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))

build-docker: ## Build the docker image
docker build --build-arg BUILD_DATE="$$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--build-arg VCS_REF="$$(git rev-parse --short HEAD)" \
-t graze/sprout .

# Testing

test: ## Run the unit and integration testsuites.
Expand All @@ -42,20 +55,18 @@ test-unit: ## Run the unit testsuite.
${DOCKER_RUN} vendor/bin/phpunit --testsuite unit

test-lowest: ## Test using the lowest possible versions of the dependencies
test-lowest: PREFER_LOWEST=--prefer-lowest --prefer-stable
test-lowest: PREFER_LOWEST=--prefer-lowest
test-lowest: build-update test

test-matrix: ## Run the unit tests against multiple targets.
${MAKE} IMAGE="php:5.6-alpine" test
${MAKE} IMAGE="php:7.0-alpine" test
${MAKE} IMAGE="php:7.1-alpine" test
${MAKE} IMAGE="hhvm/hhvm:latest" test

test-matrix-lowest: ## Run the unit tests against
${MAKE} build-update PREFER_LOWEST='--prefer-lowest --prefer-stable'
${MAKE} test-matrix
test-matrix-lowest: ## Test all version, with the lowest version
${MAKE} test-matrix PREFER_LOWEST=--prefer-lowest
${MAKE} build-update

test-matrix: ## Run the unit tests against multiple targets.
${MAKE} PHP_VER="7.0" build-update test
${MAKE} PHP_VER="7.1" build-update test
${MAKE} PHP_VER="7.2" build-update test

test-coverage: ## Run all tests and output coverage to the console.
${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-text

Expand Down
104 changes: 64 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sprout
# Sprout

[![Latest Version on Packagist](https://img.shields.io/packagist/v/graze/sprout.svg?style=flat-square)](https://packagist.org/packages/graze/sprout)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
Expand All @@ -7,59 +7,83 @@
[![Quality Score](https://img.shields.io/scrutinizer/g/graze/sprout.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/sprout)
[![Total Downloads](https://img.shields.io/packagist/dt/graze/sprout.svg?style=flat-square)](https://packagist.org/packages/graze/sprout)

>You now have a copy of the files in this repository, in a new git repository with no previous history that can you manipulate and push to other remote repositories.
>
> ## Continuous Integration
>
>Your project should make use of the following remote CI services:
>
> ### [Travis CI](https://travis-ci.org/graze/) - automated testing
>
> 1. Log-in with github
> 1. visit: https://travis-ci.org/profile/graze
> 1. Click `sync with github`
> 1. Enable your project
>
> ### [Scrutinizer CI](https://scrutinizer-ci.com/organizations/graze/repositories) - code quality
>
> 1. Log-in via github
> 1. Click `+ Add Repository`
> 1. Select `graze` as the organisation (ask a graze/@open-source-team member for access)
> 1. Entry the repository name
> 1. Click `Add Repository`
> 1. Click on the 🔧 > `Configuration` set `Shared Config` to `graze/standards + open source`
>
> ### [Packagist](https://packagist.org/graze) - package repository
>
> 1. Log-in using the graze account
> 1. Click `Submit`
> 1. Paste the `git` url (e.g. `git@github.com:graze/sprout.git`)
> 1. Click `Check`
> 1. Follow the instructions on auto updating the project in packagist
>
> ## Github Teams
>
> Add this project to the graze [Open Source](https://github.com/orgs/graze/teams/open-source-team/members) team to allows others to contribute to this project
Sprout is a tool to help Dump, Truncate and Seed development data into your databases.

![](https://78.media.tumblr.com/534425eb11706448af8ce5838629f76d/tumblr_inline_n9t8gdzC7p1qzjzhu.gif)

1. Seed sql data from local files
1. Dump data from mysql tables
1. Performs actions in parallel
1. Handle multiple groups of seed data (for example, `static`, `core`, `testing`)

## Install

Via Composer

```bash
composer require graze/sprout
~$ composer require graze/sprout
```

Via docker

```bash
`$ docker run -v [volumes] --rm graze/sprout [command]
```

## Usage

```php
$skeleton = new Graze\Sprout\Skeleton('big', 'small', 'dog');
echo $skeleton->sing();
### Quick Start

```bash
~$ # Dump all tables you are interested in
~$ sprout dump --config=config/sprout.yml --group=core a_schema:table_1,table_2 ...
~$ # Store the data in your repository of choice
~$ git add /seed/data/*
~$ # Seed the data from your seed data
~$ sprout seed --config=config/sprout.yml --group=core
```

### Seeding

```bash
~$ sprout seed [--config=<path>] [--group=<group>] [--chop] [<schema>[:<table>,...]] ...
~$ sprout seed --config=config/sprout.yml the_schema
~$ sprout seed --config=config/sprout.yml --chop the_schema
~$ sprout seed --config=config/sprout.yml the_schema:country
~$ sprout seed --config=config/sprout.yml --chop the_schema:country other_schema:planets
~$ sprout seed --config=config/sprout.yml --group=core
~$ sprout seed --config=config/sprout.yml --group=core the_schema
~$ sprout seed --config=config/sprout.yml --chop --group=extra
```
## Change log
### Truncating the data from all the tables in a schema
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
```bash
~$ sprout chop [--config=<path>] [--group=<group>] [<schema>[:<table>,...]] ...
~$ sprout chop --config=config/sprout.yml the_schema
~$ sprout chop --config=config/sprout.yml the_schema:country
~$ sprout chop --config=config/sprout.yml --group=core the_schema
~$ sprout chop --config=config/sprout.yml --group=extra the_schema:country
```
### Dumping the data from all tables in a schema
```bash
~$ sprout dump [--config=<path>] [--group=<group>] [<schema>[:<table>,...]] ...
~$ sprout dump --config=config/sprout.yml the_schema
~$ sprout dump --config=config/sprout.yml the_schema:country
~$ sprout dump --config=config/sprout.yml --group=core
~$ sprout dump --config=config/sprout.yml --group=core the_schema:country
```
## Testing
Expand Down
3 changes: 2 additions & 1 deletion bin/sprout
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

<?php

use Graze\Sprout\Command\ChopCommand;
use Graze\Sprout\Command\DumpCommand;
use Graze\Sprout\Command\SeedCommand;
use Symfony\Component\Console\Application;

require_once '../vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

mb_internal_encoding("UTF-8");
mb_http_output("UTF-8");
Expand Down
13 changes: 13 additions & 0 deletions bin/wait-for-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

i=0
while ! nc "$1" "$2" >/dev/null 2>&1 < /dev/null; do
i=`expr $i + 1`
if [ $i -ge 50 ]; then
echo "$(date) - $1:$2 still not reachable, giving up"
exit 1
fi
echo "$(date) - waiting for $1:$2..."
sleep 1
done
echo "$1 connection established"
Loading

0 comments on commit c7642c3

Please sign in to comment.