Skip to content

Commit

Permalink
Merge branch 'release/v1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
cytodev committed May 15, 2020
2 parents 25a9e71 + a9058bb commit 79a28a5
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 37 deletions.
36 changes: 24 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,46 @@ Changes are documented in the following order:
5. Fixed
6. Security

## [Unreleased](https://github.com/CytoDev/docker-compose-wrapper/compare/master...dev)
## [Unreleased](https://github.com/cytodev/docker-compose-wrapper/compare/master...dev)

## [1.2.0] - 2020-05-15
### Added
- add `dockerw create` command
- add error message when an unsupported operation is requested

### Removed
- removed redundant call to a container specific script

### Fixed
- fixed directory path when selecting host directory in standalone installations

## [1.1.0] - 2020-05-14
### Added
- add Instance naming support
- add base Ubuntu releases to environments
- add default host Dockerfile
- add `gpg` to standard host release
- add `gpg` to standard host container
- add `dockerw logs` command
- add `shared-content-sync` to default shared directory
- add shared directories
- add standalone functionality

### Changed
- Default `.bashrc` file
- Moved shared content to shared directory
- updated default `.bashrc` file
- moved shared content to shared directory

### Removed
- `dockerw ssh` command in favour of `dockerw enter <container>`
- `dockerw composer` command because it is too specific
- removed `dockerw ssh` command in favour of `dockerw enter <container>`
- removed `dockerw composer` command because it is too specific

### Fixed
- Fixed symbolic link overriding issues in `dockerw setup`
- Fixed existential crisis when executed outside of own directory
- Fixed function calls calling subshells
- fixed symbolic link overriding issues in `dockerw setup`
- fixed existential crisis when executed outside of own directory
- fixed function calls calling subshells

## [1.0.0] - 2019-11-05
- Initial release
- initial release

[1.1.0]: https://github.com/CytoDev/docker-compose-wrapper/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/CytoDev/docker-compose-wrapper/compare/e61315f...v1.0.0
[1.2.0]: https://github.com/cytodev/docker-compose-wrapper/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/cytodev/docker-compose-wrapper/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/cytodev/docker-compose-wrapper/compare/e61315f...v1.0.0
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
A "simple" drop-in container wrapper that requires all of your configuration

## index
- [Notice](#Notice)
- [Prerequisites](#Prerequisites)
- [How to get started](#How-to-get-started)
- [Standalone (preferred)](#Standalone-(preferred))
- [How does git work again?](#How-does-git-work-again?)
- [Why UNIX only?](#Why-UNIX-only?)
- [Notice](#notice)
- [Prerequisites](#prerequisites)
- [How to get started](#how-to-get-started)
- [Standalone (preferred)](#standalone-preferred)
- [How does git work again?](#how-does-git-work-again)
- [Why UNIX only?](#why-unix-only)
- [In-project or local](#in-project-or-local)
- [Contributions](#Contributions)
- [Creating containers](#creating-containers)
- [Contributions](#contributions)

## Notice
This repository requires **a lot** of configuration on your part. This is to be expected, seeing how docker also requires lots of configuration and I didn't want to limit my efforts to a single project. I would advise against using this repository when you're trying to set up a single local docker environment (see [lando](https://lando.dev/) or [devilbox](http://devilbox.org/)). However, when you're like me and manage lots of projects this might just be the tool you need.
Expand Down Expand Up @@ -39,7 +40,7 @@ $ rm -rf docker-compose-wrapper
Now you're free to use the `dockerw` command just like you're used to using the `git` command.

##### How does git work again?
Simple, type `git init` to start your project -- this translates to `dockerw init` to start a local container cluster. This setup does require some manual actions inside the `.dockerw` directory though (see the [example branch](https://github.com/CytoDev/docker-compose-wrapper/tree/example)).
Simple, type `git init` to start your project -- this translates to `dockerw init` to start a local container cluster.

##### Why UNIX only?
Because of the directory structure and installation process. I haven't used any other OS on a serious level since ever, so I will leave integration to the contributors -- they will know what to do.
Expand All @@ -51,15 +52,23 @@ Probably preferred on NT (MS Windows) machines or restricted UNIX systems
$ cd <your_development_directory>
$ git clone [email protected]:cytodev/docker-compose-wrapper.git .dockerw
$ cd .dockerw
#[ you might want to stick to the version you installed ]#######################
#[ if not, you can skip the next line ]#########################################
$ git remote rm origin
#[ these next steps are for easy access, but not required ]#####################
$ cd ../
$ ln -s ./.dockerw/dockerw
```

Please note that you can only use the `dockerw` command _in this directory_ and only by specifying that you want to execute this command via the `./<file>`. (mileage
may vary on NT)

See the [example branch](https://github.com/CytoDev/docker-compose-wrapper/tree/example) to get a general idea on how to set this repository up in your use-case.
## Creating containers
Creating new containers can be done by using the [`dockerw create`](https://github.com/cytodev/docker-compose-wrapper/blob/v1.2.0/dockerw#L320) command added in [v1.2.0](https://github.com/CytoDev/docker-compose-wrapper/blob/master/CHANGELOG.md#120---2020-05-15). This command will ask some basic questions in order to set up the scaffolding needed for a container.

See the [example branch](https://github.com/cytodev/docker-compose-wrapper/tree/example) to get a general idea on how to set this repository up in your use-case.

## Contributions
You are more than welcome to submit issues as well as feature requests or just a 'how-ya-doin' in the [issue tracker](https://github.com/CytoDev/python-sdwc/issues/new). Contributing to the project can be done by forking it and submitting a pull request once it's all tested and tidy.
You are more than welcome to submit issues as well as feature requests in the [issue tracker](https://github.com/cytodev/docker-compose-wrapper/issues/new).

Contributing to the project can be done by forking it and submitting a pull request once it's all tested and tidy.
140 changes: 125 additions & 15 deletions dockerw
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#|
#| {e:1;39m}{SELF}{e:m} [{e:32m}<options>{e:m}] [{e:37m}--{e:m}] init
#| {e:1;39m}{SELF}{e:m} [{e:32m}<options>{e:m}] [{e:37m}--{e:m}] setup
#| {e:1;39m}{SELF}{e:m} [{e:32m}<options>{e:m}] [{e:37m}--{e:m}] create
#| {e:1;39m}{SELF}{e:m} [{e:32m}<options>{e:m}] [{e:37m}--{e:m}] env
#| {e:1;39m}{SELF}{e:m} [{e:32m}<options>{e:m}] [{e:37m}--{e:m}] up
#| {e:1;39m}{SELF}{e:m} [{e:32m}<options>{e:m}] [{e:37m}--{e:m}] list
Expand All @@ -24,6 +25,7 @@
#| {e:3;33m}Operations:{e:m}
#| {e:34m}init{e:m} Initializes a {SELF} project (similar to git init)
#| {e:34m}setup{e:m} Enters setup mode to build the .env file
#| {e:34m}create{e:m} Creates the basic files required to set up a container
#| {e:34m}env{e:m} Displays .env files in use by the defined containers
#| {e:34m}up{e:m} Builds and starts the defined containers
#| {e:34m}list{e:m} Lists all containers
Expand Down Expand Up @@ -315,6 +317,105 @@ function _init {
fi
}

function _create {
local container_name;
local container_from_name;
local container_from_version;
local working_dir;

while [[ -z "${container_name}" ]]; do
read -e -r -p "Container name: " container_name </dev/tty;
done

if [[ -d "${OWN_DIRECTORY}/containers/${container_name}" ]]; then
if ! _ask "${container_name} already exists, overwrite?" "n"; then
_create;

return ${?};
fi
fi

while [[ -z "${container_from_name}" ]]; do
read -e -r -p "From container name: " container_from_name </dev/tty;
done

while [[ -z "${container_from_version}" ]]; do
read -e -r -p "From container version: " container_from_version </dev/tty;
done

while [[ -z "${working_dir}" ]]; do
read -e -r -p "Working directory: " working_dir </dev/tty;
done

if ! _ask "Accept configuration?" "y"; then
if ! _ask "Retry configuration?" "y"; then
return 1;
fi

_create;

return ${?};
fi

mkdir -p "${OWN_DIRECTORY}/containers/${container_name}";
mkdir -p "${OWN_DIRECTORY}/containers/${container_name}/data";
touch "${OWN_DIRECTORY}/containers/${container_name}/data/.gitkeep";
mkdir -p "${OWN_DIRECTORY}/env/${container_name}";

cat <<EOF > "${OWN_DIRECTORY}/containers/${container_name}/compose.yml";
container-${container_name}:
image: container:${container_name}\${${container_from_name^^}_VERSION}
container_name: ${container_name}\${${container_from_name^^}_VERSION}
hostname: ${container_name}
restart: unless-stopped
working_dir: ${working_dir}
network_mode: host
build:
context: ./containers/${container_name}/
args:
- ARG_USER_ID=\${USER_ID}
- ARG_GROUP_ID=\${GROUP_ID}
- ARG_${container_from_name^^}_VERSION=\${${container_from_name^^}_VERSION:-latest}
volumes: *host-volumes
depends_on:
- container-host
EOF

cat <<EOF > "${OWN_DIRECTORY}/containers/${container_name}/Dockerfile";
ARG ARG_${container_from_name^^}_VERSION=\${ARG_${container_from_name^^}_VERSION}
FROM ${container_from_name}:\${ARG_${container_from_name^^}_VERSION}
# copy specific overwrites from container data
COPY containers/${container_from_name}/data /
# this is the only place we can move over the hosts file
COPY shared/etc/hosts /etc/hosts
# initially copy the shared directory but mount it afterwards
COPY shared /shared
# set up shared content links
RUN /shared/usr/local/bin/shared-content-sync
# user creation
ARG ARG_USER_ID=\${ARG_USER_ID}
ARG ARG_GROUP_ID=\${ARG_GROUP_ID}
RUN if ! getent group \${ARG_GROUP_ID} &> /dev/null; then groupadd -g \${ARG_GROUP_ID} development; fi \\
&& useradd -u \${ARG_USER_ID} -g \${ARG_GROUP_ID} -G 100,27,33 -m -d /home/development -s /bin/bash development \\
&& echo 'development:development' | chpasswd
USER \${ARG_USER_ID}:\${ARG_GROUP_ID}
EOF

_print -i "Wrote container configuration to %s" "${OWN_DIRECTORY}/containers/${container_name}";

cat <<EOF > "${OWN_DIRECTORY}/env/${container_name}/${container_from_version}.env";
${container_from_name^^}_VERSION=${container_from_version}
EOF

_print -i "Wrote container environment to %s" "${OWN_DIRECTORY}/env/${container_name}/${container_from_version}.env";
}

function _setup {
local input_file_stop=${IFS};
local payload=();
Expand All @@ -335,6 +436,8 @@ function _setup {
done

instance_name="${choice}-";

_print -v "INSTANCE_NAME=%s" "${choice}";
fi

printf "version: \"%s\"\n\nservices:" "${DOCKER_COMPOSE_VERSION}" > "${OWN_DIRECTORY}/docker-compose.yml";
Expand Down Expand Up @@ -444,24 +547,33 @@ function _setup {
choice=;

while [[ -z "${choice}" ]]; do
cd "${RESTORE}" || exit 1;

read -e -r -p "Host data directory: " choice </dev/tty;

if ! choice="$(realpath "${choice}")"; then
choice="$(realpath "${choice}")";

if [[ ! -d "${choice}" ]]; then
_print -w "Unable to resolve path of '%s'" "${choice}";

choice=;

continue;
fi

cd "${OWN_DIRECTORY}" || exit 1;
done

_print -v "DATA_DIR=%s" "${choice}";
payload+=("DATA_DIR=${choice}");

choice=$(_share_directory "SSH" "${HOME}/.ssh");
[[ -n "${choice}" ]] && payload+=("USER_SSH_DIR=${choice}");
_print -v "USER_SSH_DIR=%s" "${choice}";

choice=$(_share_directory "cache" "${HOME}/.cache");
[[ -n "${choice}" ]] && payload+=("USER_CACHE_DIR=${choice}");
_print -v "USER_CACHE_DIR=%s" "${choice}";
fi

_print -v -s "building environment file...";
Expand Down Expand Up @@ -498,9 +610,6 @@ function _env {
}

function _up {
local data_path;
local www_path;

if ! _verify_env; then
return 1;
fi
Expand All @@ -518,18 +627,8 @@ function _up {
_print -i "Docker image built successfully";

if docker-compose up -d; then
PIPE_SEVERITY="-c";

while read -r data_path www_path; do
[[ -z "${data_path}" ]] || [[ -z "${www_path}" ]] && continue;

_print -v "exec data2www '%s' '%s'" "${data_path}" "${www_path}";

docker-compose exec -T container-php data2www "${data_path}" "${www_path}" 2> >(_print_pipe) & disown;
done < "${OWN_DIRECTORY}/config/data2www.cfg"
[[ $(_get_option "auto_enter") -eq 0 ]] && _enter "host";
fi

[[ $(_get_option "auto_enter") -eq 0 ]] && _enter "host";
}

function _list {
Expand Down Expand Up @@ -623,6 +722,11 @@ function main {
"init")
_init;

status=${?};
;;
"create")
_create;

status=${?};
;;
"setup")
Expand Down Expand Up @@ -670,6 +774,12 @@ function main {

status=${?};
;;
*)
_print -c "Invalid operation '%s'" "${ARGV[1]}";
_print -i "see '%s --help' for a list of available operations" "${SELF}";

status=1;
;;
esac

return ${status};
Expand Down

0 comments on commit 79a28a5

Please sign in to comment.