Skip to content

Commit c7642c3

Browse files
author
Harry Bragg
authored
Initial, sort of over engineered version (#1)
* 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
1 parent f010fe5 commit c7642c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2176
-1161
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ language: php
22

33
dist: trusty
44

5+
## Cache composer bits
56
cache:
67
directories:
78
- $HOME/.composer/cache/files
89

910
php:
10-
- 5.6
1111
- 7.0
1212
- 7.1
13-
- hhvm
13+
- 7.2
1414
- nightly
1515

1616
env:
@@ -22,6 +22,7 @@ matrix:
2222
- php: nightly
2323

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

2728
script:

Dockerfile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
FROM php:7.1-alpine
1+
FROM composer AS build
2+
3+
WORKDIR /app
4+
COPY src /app/src
5+
COPY composer.json /app/composer.json
6+
COPY composer.lock /app/composer.lock
7+
8+
RUN composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader --prefer-dist
9+
10+
FROM graze/php-alpine:7.2 AS run
211

312
RUN set +xe \
413
&& apk add --no-cache \
514
mariadb-client
615

16+
WORKDIR /app
17+
COPY --from=build /app/src /app/src
18+
COPY --from=build /app/vendor /app/vendor
719
COPY bin /app/bin
8-
COPY src /app/src
9-
COPY vendor /app/vendor
1020

11-
VOLUME ["/seed", "/app/config"]
21+
ARG BUILD_DATE
22+
ARG VCS_REF
23+
24+
LABEL org.label-schema.schema-version="1.0" \
25+
org.label-schema.vendor="graze" \
26+
org.label-schema.name="morphism" \
27+
org.label-schema.description="seed your databases" \
28+
org.label-schema.vcs-url="https://github.com/graze/sprout" \
29+
org.label-schema.vcs-ref=$VCS_REF \
30+
org.label-schema.build-date=$BUILD_DATE \
31+
maintainer="developers@graze.com" \
32+
license="MIT"
33+
34+
VOLUME ["/app/config", "/seed"]
1235

1336
ENTRYPOINT ["php", "/app/bin/sprout"]
1437
CMD ["list"]

Makefile

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
SHELL = /bin/sh
22

3-
DOCKER ?= $(shell which docker)
3+
DOCKER = $(shell which docker)
4+
PHP_VER := 7.2
5+
IMAGE := graze/php-alpine:${PHP_VER}-test
46
VOLUME := /srv
5-
IMAGE ?= graze/php-alpine:test
6-
DOCKER_RUN := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME} ${IMAGE}
7+
DOCKER_RUN_BASE := ${DOCKER} run --rm -t -v $$(pwd):${VOLUME} -w ${VOLUME}
8+
DOCKER_RUN := ${DOCKER_RUN_BASE} ${IMAGE}
79

810
PREFER_LOWEST ?=
911

1012
.PHONY: build build-update composer-% clean help run
1113
.PHONY: lint lint-fix
12-
.PHONY: test test-unit test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover
14+
.PHONY: test test-unit test-integration test-lowest test-matrix test-coverage test-coverage-html test-coverage-clover
1315

1416
.SILENT: help
1517

1618
# Building
1719

18-
build: ## Download the dependencies then build the image :rocket:.
19-
make 'composer-install --prefer-dist --optimize-autoloader'
20+
build: ## Install the dependencies
21+
build: ensure-composer-file
22+
make 'composer-install --optimize-autoloader --prefer-dist ${PREFER_LOWEST}'
2023

21-
build-update: ## Update all dependencies
22-
make 'composer-update --prefer-dist --optimize-autoloader ${PREFER_LOWEST}'
24+
build-update: ## Update the dependencies
25+
build-update: ensure-composer-file
26+
make 'composer-update --optimize-autoloader --prefer-dist ${PREFER_LOWEST}'
27+
28+
ensure-composer-file: # Update the composer file
29+
make 'composer-config platform.php ${PHP_VER}'
2330

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

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

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

4457
test-lowest: ## Test using the lowest possible versions of the dependencies
45-
test-lowest: PREFER_LOWEST=--prefer-lowest --prefer-stable
58+
test-lowest: PREFER_LOWEST=--prefer-lowest
4659
test-lowest: build-update test
4760

48-
test-matrix: ## Run the unit tests against multiple targets.
49-
${MAKE} IMAGE="php:5.6-alpine" test
50-
${MAKE} IMAGE="php:7.0-alpine" test
51-
${MAKE} IMAGE="php:7.1-alpine" test
52-
${MAKE} IMAGE="hhvm/hhvm:latest" test
53-
54-
test-matrix-lowest: ## Run the unit tests against
55-
${MAKE} build-update PREFER_LOWEST='--prefer-lowest --prefer-stable'
56-
${MAKE} test-matrix
61+
test-matrix-lowest: ## Test all version, with the lowest version
62+
${MAKE} test-matrix PREFER_LOWEST=--prefer-lowest
5763
${MAKE} build-update
5864

65+
test-matrix: ## Run the unit tests against multiple targets.
66+
${MAKE} PHP_VER="7.0" build-update test
67+
${MAKE} PHP_VER="7.1" build-update test
68+
${MAKE} PHP_VER="7.2" build-update test
69+
5970
test-coverage: ## Run all tests and output coverage to the console.
6071
${DOCKER_RUN} phpdbg7 -qrr vendor/bin/phpunit --coverage-text
6172

README.md

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sprout
1+
# Sprout
22

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

10-
>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.
11-
>
12-
> ## Continuous Integration
13-
>
14-
>Your project should make use of the following remote CI services:
15-
>
16-
> ### [Travis CI](https://travis-ci.org/graze/) - automated testing
17-
>
18-
> 1. Log-in with github
19-
> 1. visit: https://travis-ci.org/profile/graze
20-
> 1. Click `sync with github`
21-
> 1. Enable your project
22-
>
23-
> ### [Scrutinizer CI](https://scrutinizer-ci.com/organizations/graze/repositories) - code quality
24-
>
25-
> 1. Log-in via github
26-
> 1. Click `+ Add Repository`
27-
> 1. Select `graze` as the organisation (ask a graze/@open-source-team member for access)
28-
> 1. Entry the repository name
29-
> 1. Click `Add Repository`
30-
> 1. Click on the 🔧 > `Configuration` set `Shared Config` to `graze/standards + open source`
31-
>
32-
> ### [Packagist](https://packagist.org/graze) - package repository
33-
>
34-
> 1. Log-in using the graze account
35-
> 1. Click `Submit`
36-
> 1. Paste the `git` url (e.g. `git@github.com:graze/sprout.git`)
37-
> 1. Click `Check`
38-
> 1. Follow the instructions on auto updating the project in packagist
39-
>
40-
> ## Github Teams
41-
>
42-
> 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
10+
Sprout is a tool to help Dump, Truncate and Seed development data into your databases.
4311

12+
![](https://78.media.tumblr.com/534425eb11706448af8ce5838629f76d/tumblr_inline_n9t8gdzC7p1qzjzhu.gif)
13+
14+
1. Seed sql data from local files
15+
1. Dump data from mysql tables
16+
1. Performs actions in parallel
17+
1. Handle multiple groups of seed data (for example, `static`, `core`, `testing`)
4418

4519
## Install
4620

4721
Via Composer
4822

4923
```bash
50-
composer require graze/sprout
24+
~$ composer require graze/sprout
25+
```
26+
27+
Via docker
28+
29+
```bash
30+
`$ docker run -v [volumes] --rm graze/sprout [command]
5131
```
5232

5333
## Usage
5434

55-
```php
56-
$skeleton = new Graze\Sprout\Skeleton('big', 'small', 'dog');
57-
echo $skeleton->sing();
35+
### Quick Start
36+
37+
```bash
38+
~$ # Dump all tables you are interested in
39+
~$ sprout dump --config=config/sprout.yml --group=core a_schema:table_1,table_2 ...
40+
41+
~$ # Store the data in your repository of choice
42+
~$ git add /seed/data/*
43+
44+
~$ # Seed the data from your seed data
45+
~$ sprout seed --config=config/sprout.yml --group=core
46+
```
47+
48+
### Seeding
49+
50+
```bash
51+
~$ sprout seed [--config=<path>] [--group=<group>] [--chop] [<schema>[:<table>,...]] ...
52+
53+
~$ sprout seed --config=config/sprout.yml the_schema
54+
~$ sprout seed --config=config/sprout.yml --chop the_schema
55+
56+
~$ sprout seed --config=config/sprout.yml the_schema:country
57+
~$ sprout seed --config=config/sprout.yml --chop the_schema:country other_schema:planets
58+
59+
~$ sprout seed --config=config/sprout.yml --group=core
60+
~$ sprout seed --config=config/sprout.yml --group=core the_schema
61+
~$ sprout seed --config=config/sprout.yml --chop --group=extra
5862
```
5963
60-
## Change log
64+
### Truncating the data from all the tables in a schema
6165
62-
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
66+
```bash
67+
~$ sprout chop [--config=<path>] [--group=<group>] [<schema>[:<table>,...]] ...
68+
69+
~$ sprout chop --config=config/sprout.yml the_schema
70+
~$ sprout chop --config=config/sprout.yml the_schema:country
71+
72+
~$ sprout chop --config=config/sprout.yml --group=core the_schema
73+
~$ sprout chop --config=config/sprout.yml --group=extra the_schema:country
74+
```
75+
76+
### Dumping the data from all tables in a schema
77+
78+
```bash
79+
~$ sprout dump [--config=<path>] [--group=<group>] [<schema>[:<table>,...]] ...
80+
81+
~$ sprout dump --config=config/sprout.yml the_schema
82+
~$ sprout dump --config=config/sprout.yml the_schema:country
83+
84+
~$ sprout dump --config=config/sprout.yml --group=core
85+
~$ sprout dump --config=config/sprout.yml --group=core the_schema:country
86+
```
6387
6488
## Testing
6589

bin/sprout

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
<?php
44

5+
use Graze\Sprout\Command\ChopCommand;
56
use Graze\Sprout\Command\DumpCommand;
67
use Graze\Sprout\Command\SeedCommand;
78
use Symfony\Component\Console\Application;
89

9-
require_once '../vendor/autoload.php';
10+
require_once __DIR__ . '/../vendor/autoload.php';
1011

1112
mb_internal_encoding("UTF-8");
1213
mb_http_output("UTF-8");

bin/wait-for-db.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
i=0
4+
while ! nc "$1" "$2" >/dev/null 2>&1 < /dev/null; do
5+
i=`expr $i + 1`
6+
if [ $i -ge 50 ]; then
7+
echo "$(date) - $1:$2 still not reachable, giving up"
8+
exit 1
9+
fi
10+
echo "$(date) - waiting for $1:$2..."
11+
sleep 1
12+
done
13+
echo "$1 connection established"

0 commit comments

Comments
 (0)