Skip to content

Commit

Permalink
update to more flexible workflow scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jsatt committed Aug 25, 2020
1 parent 6a44c82 commit a92e313
Show file tree
Hide file tree
Showing 27 changed files with 736 additions and 206 deletions.
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# How are you using Docker for development?
# full - Docker for running app and all dependencies (recommmended)
# deps - Docker for running dependencies, but running app natively
# none - Running app and all dependencies natively
DEV_DOCKER_WORKFLOW=full
#DEV_DOCKER_WORKFLOW=deps
#DEV_DOCKER_WORKFLOW=none

## ENVIRONMENT CONFIG
# choose a debugger tool, pdb, ipdb, bpdb, etc.
#PYTHONBREAKPOINT=ipdb.set_trace
# put ipython configs somewhere persistent, so you have history between Docker reboots
# Not needed for deps or none workflows.
#IPYTHONDIR=/usr/src/app/.ipython

## DOCKER COMPOSE SETTINGS

#COMPOSE_APP_PATH=.
Expand Down
Empty file added docker/init/db/empty
Empty file.
78 changes: 78 additions & 0 deletions docker/utils/adminer/plugins/fill-login-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Fill login form automaticaly
*
* Install to Adminer on http://www.adminer.org/plugins/
* @author Pavel Kutáč, http://www.kutac.cz/
*
*/
class FillLoginForm {
private $system;
private $server;
private $name;
private $pass;
private $database;

/**
* Initialize plugin for filling login form
* @param $system - Set driver
* server - MySQL
* sqlite - SQLite3
* sqlite2 - SQLite2
* pgsql - PostgreeSQL
* oracle - Oracle
* mssql - MS SQL
* firebird - Firebird (alpha)
* simpledb - SimpleDB
* mongo - MongoDB
* elastic - Elasticsearch
*
* @param $server - Server to log in, default: localhost
* @param $name - User name
* @param $pass - Password to database
* @param $database - Name of database
*/
public function __construct($system = "server", $server = false, $name = false, $pass = false, $database = false){
$this->system = $system;
$this->server = $server;
$this->name = $name;
$this->pass = $pass;
$this->database = $database;
}

public function loginForm(){
if(empty($_GET[DRIVER]) && empty($_GET["username"]) && empty($_GET["db"]) ){?>
<script<?php echo nonce(); ?>>
document.addEventListener("DOMContentLoaded", function(event) {
var dr = qs("option[value='<?php echo $this->system; ?>']");
if(dr){ dr.selected = true; }

<?php if(!empty($this->server)){ ?>
var s = qs("input[name='auth[server]']");
if(s && s.value.trim() == ""){ s.value = "<?php echo $this->server ?>"; }
<?php }

if(!empty($this->name)){ ?>
var l = qs("input[name='auth[username]']");
if(l && l.value.trim() == ""){ l.value = "<?php echo $this->name ?>"; }
<?php }

if(!empty($this->pass)){ ?>
var p = qs("input[name='auth[password]']");
if(p && p.value.trim() == ""){ p.value = "<?php echo $this->pass ?>"; }
<?php }

if(!empty($this->database)){ ?>
var d = qs("input[name='auth[db]']");
if(d && d.value.trim() == ""){ d.value = "<?php echo $this->database ?>"; }
<?php } ?>
});
</script>
<?php
}
return null;
}
}

return new FillLoginForm($_ENV['ADMINER_SYSTEM'], $_ENV['ADMINER_SERVER'], $_ENV['ADMINER_USER'], $_ENV['ADMINER_PASSWORD'], $_ENV['ADMINER_DB'])
?>
90 changes: 70 additions & 20 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Developer Workflow Scripts
===========================================
==========================

The scripts in this directory are intended to improve developer workflow when working with the
Docker toolchain. All scripts contain a help message outlining the purpose and usage of each
Expand All @@ -8,6 +8,15 @@ quite complex, and these scripts are intended to get you kickstarted, but you li
use the `docker` and `docker-compose` commands directly at some point in the near future. The
[Docker docs](https://docs.docker.com/reference/) are your friend.

You can configure which Docker services are managed by these scripts by changing the
DEV_DOCKER_WORKFLOW variable in your .env file. Depending on this configuration some scripts will
act differently.

* full - application and dependency services are all run in Docker
* deps - only dependencies are run in Docker, devs are responsible for setting up application
environment
* none - Docker is not used at all, devs are responsible for setting up all dependencies.


setup
-----
Expand All @@ -16,13 +25,17 @@ This is the script intended to prepare your system by installing the Docker tool
the images and restoring a fresh database for the project. Due to the installation process for Mac,
you should run `setup_docker` first.

Supported Workflows: `full`, partial for `deps`

setup_docker
------------

This script will install Docker and docker-compose. On Linux systems this is called as part of the
`setup` script and does not need to be run separately. For Mac, this script should be run before
running `setup`.

Supported Workflows: `full`, `deps`

start
-----

Expand All @@ -36,56 +49,70 @@ If you provide the `-d` flag to detach from the services and run them in the bac
be returned to your shell. You can use the `attach` script to connect to all or specific services
at any time. You will need to use the `stop` script to stop services that are detached.

Supported Workflows: `full`, partial for `deps`

stop
----

This script will stop all or specfic services, whether they are detached or attached in another
terminal.

Supported Workflows: `full`, partial for `deps`

update
------

This script is intended to be run when pulling down a large changeset, i.e. pulling a new branch or
latest master. It will rebuild your images and containers, installing new requirements, and run
latest main branch. It will rebuild your images and containers, install new requirements, and run
migrations.

Supported Workflows: `full`, `deps`, `none`

install
-------

This is intended to abstract away a large number of complexities when working with the project. You
should specify whether you installing a Python or System (apt) package and this script will
take the appropriate steps to make sure the package is installed and added to the correct
requirements file (pyproject.toml or package.json). You can provide the `--dev` and `--no-save`
flags to modify this functionality as needed.
should specify whether you installing a Python or System (apt) package and this script will take
the appropriate steps to make sure the package is installed and added to the correct requirements
file. You can provide the `--dev` and `--no-save` flags to modify this functionality as needed.

Supported Workflows: `full`, partial for `deps` and `none`

migrate
-------

Use this script to abstract some complexities in managing migrations within Docker. When run
directly, the `run` command is assumed and migrations will be run, but you can also use the `make`
and `show` commands to create and list migrations. Most options for equivalent Django commands
should translate directly, when provided after the command.
Use this script to abstract some complexities in managing migrations. When run directly, the `run`
command is assumed and migrations will be run, but you can also use the `make` and `show` commands
to create and list migrations. Most options for equivalent Django commands should translate
directly, when provided after the command.

Supported Workflows: `full`, `deps`, `none`

test
----

This will run the appropriate unittesting suite. While it currently only supports Python/Django
tests, it is intended that in the future javascript tests will be decoupled from the build process
allowing this to manage those as well.
This will run the unittesting suite. Any additional args passed to this command are passed directly
to the test runner.

Supported Workflows: `full`, `deps`, `none`

console
-------

This will allow you to connect to the services via the appropriate interactive console. Currently
supported are `bash` to use bash on the primary web service, `sudo` to use bash as sudo, `python`
to use Django's shell_plus command, and `mysql` to get a MySQL console.
to use Django's shell_plus command, and `sql` to get a SQL console.

Supported Workflows: `full`, partial for `deps` and `none`

attach
------

This can be used to attach to a specific service's output console. Whether it's running in detached
mode or you simply want to see that services output by itself in a separate terminal.

Supported Workflows: `full`, partial for `deps`

restore_db
----------

Expand All @@ -95,6 +122,16 @@ files located in `docker/init/db`. The restore files **must** exist for this scr
All migrations in your current checkout of the codebase will be run at the end of the restore
unless using the `--no-migrate` flag.

Supported Workflows: `full`, `deps`

manage
------

This is simply a convenience command which calls Django's `manage.py` command in the appropriate
environment based on selected dev workflow and passes all arg to the command.

Supported Workflows: `full`, `deps`, `none`

cleanup
-------

Expand All @@ -109,13 +146,17 @@ cache. However, this takes up a large amount of space on your system and it's re
occasionally run `cleanup --docker` to also remove any Docker artifacts that are no longer used,
freeing up space on your system

Supported Workflows: `full`, `deps`, partial for `none`

teardown
--------

This will utterly and completely destroy your Docker environment, including all build files and
database volumes. There should never be any side affects outside of that environment, which can be
rebuilt using `setup`, but you will be waiting a while for it to rebuild.

Supported Workflows: `full`, `deps`

tools
-----

Expand All @@ -129,14 +170,23 @@ This script will allow you to run certain, short lived, utilities that are not s
running or developing the application, but can sometimes come in handy. See the help text of this
command to see all available utilities.

### pgadmin
### flower

This starts a web-based tool for monitoring Celery. It's recommended that you set `FLOWER_PORT` in
your .env file to expose the service on a non-random port.

Supported Workflows: `full`, `deps`

pgAdmin4 is a web-based tool for monitoring and managing Postgres databases. You will need to
configure a server connection the first time you run it (and anytime it's volume gets deleted). Use
the network alias and default Postgres username and password found in the docker-compose file for
the db service.
### dbadmin

### pgdump
Adminer is a web-based tool for monitoring and managing databases. On pageload the default
credentials shoul dbe pre-populated.

Supported Workflows: `full`, `deps`

### dbdump

This will dump the contents of the database to a file. By default it only dumps the `base_app`
database to a gzipped file.

Supported Workflows: `full`, `deps`, `none`
13 changes: 10 additions & 3 deletions scripts/attach
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/bin/bash
set -e
script_base=$(dirname "$0")
source $script_base/tools
cd $script_base/..

source $script_base/tools
load_env

POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help|?)
echo "Attach to a running service."
echo "Watch output of a running service."
echo
cecho "Usage: $(basename $0) <options> <SERVICE>" default bold
echo
Expand All @@ -28,5 +29,11 @@ while [[ $# -gt 0 ]]; do
shift
done
set -- "${POSITIONAL[@]}"
target=$1

docker-compose logs -f $1
if [ $(can_run_docker $DEV_DOCKER_WORKFLOW $target) ]; then
docker-compose logs -f $target
else
cecho "Cannot attach to '$target' while DEV_DOCKER_WORKFLOW set as '$DEV_DOCKER_WORKFLOW'. Please review your .env file." red bold
exit 1
fi
Loading

0 comments on commit a92e313

Please sign in to comment.