diff --git a/CHANGELOG.md b/CHANGELOG.md index 932672b..cabe9f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ` - - `dockerw composer` command because it is too specific + - removed `dockerw ssh` command in favour of `dockerw enter ` + - 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 diff --git a/README.md b/README.md index f816e51..08c6221 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. @@ -51,7 +52,10 @@ Probably preferred on NT (MS Windows) machines or restricted UNIX systems $ cd $ git clone git@github.com: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 ``` @@ -59,7 +63,12 @@ $ 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 `./`. (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. diff --git a/dockerw b/dockerw index 7e6c5ff..c197c31 100755 --- a/dockerw +++ b/dockerw @@ -7,6 +7,7 @@ #| #| {e:1;39m}{SELF}{e:m} [{e:32m}{e:m}] [{e:37m}--{e:m}] init #| {e:1;39m}{SELF}{e:m} [{e:32m}{e:m}] [{e:37m}--{e:m}] setup +#| {e:1;39m}{SELF}{e:m} [{e:32m}{e:m}] [{e:37m}--{e:m}] create #| {e:1;39m}{SELF}{e:m} [{e:32m}{e:m}] [{e:37m}--{e:m}] env #| {e:1;39m}{SELF}{e:m} [{e:32m}{e:m}] [{e:37m}--{e:m}] up #| {e:1;39m}{SELF}{e:m} [{e:32m}{e:m}] [{e:37m}--{e:m}] list @@ -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 @@ -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 "${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 < "${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 < "${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=(); @@ -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"; @@ -444,24 +547,33 @@ function _setup { choice=; while [[ -z "${choice}" ]]; do + cd "${RESTORE}" || exit 1; + read -e -r -p "Host data directory: " choice >(_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 { @@ -623,6 +722,11 @@ function main { "init") _init; + status=${?}; + ;; + "create") + _create; + status=${?}; ;; "setup") @@ -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};