Skip to content

Commit 0e032fc

Browse files
Merge pull request #23 from datastack-net/feature/compose-file
Feature/compose file
2 parents 070c1f5 + ac23591 commit 0e032fc

File tree

16 files changed

+811
-351
lines changed

16 files changed

+811
-351
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
COMPOSE_PATH_SEPARATOR=";"
2+
COMPOSE_FILE="${DOCKERIZED_ROOT}/docker-compose.yml"
13
DEFAULT_ARCH=x86_64
24
ALPINE_VERSION=3.14.2
35
ANSIBLE_VERSION=2.12

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ jobs:
2626
run: |
2727
bin/dockerized --shell $COMMAND -c 'echo $HOST_HOSTNAME' | tee ~/shell.log
2828
grep $(hostname) ~/shell.log
29+
IntegrationTest:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/setup-go@v2
33+
with:
34+
go-version: '1.17.8'
35+
- name: Checkout Dockerized
36+
uses: actions/checkout@v2
37+
- name: go test
38+
run: |
39+
DOCKERIZED_ROOT=$(pwd) go test -p 1 .
2940
CompileAndTest:
3041
runs-on: ${{ matrix.os }}
3142
strategy:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/*
22
.cache/*
3-
.go/*
3+
.go/*
4+
test/*

DEV.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ For example, this is how `go` is added:
77
```yaml
88
services:
99
go:
10-
<<: *default
1110
image: golang:latest
1211
entrypoint: [ "go" ]
1312
```
1413
15-
- `<<: *default` is a YAML reference that copies some default settings for the service. Just include it.
1614
- `image: golang:latest` specifies the docker image to use. You can find these on [Docker Hub](https://hub.docker.com/).
1715
- `entrypoint` is the command to run when the service starts.
1816

@@ -33,7 +31,6 @@ Replace the version tag `latest` with `${GO_VERSION}`:
3331

3432
```yaml
3533
go:
36-
<<: *default
3734
image: "golang:${GO_VERSION}"
3835
entrypoint: [ "go" ]
3936
```
@@ -60,7 +57,7 @@ dockerized gh auth login
6057
```
6158

6259
- Choose SSH, and Browser authentication
63-
- See [gh](apps/gh/Readme.md) for more information.
60+
- See [gh](apps/gh/README.md) for more information.
6461

6562
```bash
6663
# Create a PR:

README.md

Lines changed: 116 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Dockerized [![Compile and Test](https://github.com/datastack-net/dockerized/actions/workflows/test.yml/badge.svg)](https://github.com/datastack-net/dockerized/actions/workflows/test.yml)
1+
![Dockerized](dockerized-banner.png)
2+
3+
# Dockerized [![Compile and Test](https://github.com/datastack-net/dockerized/actions/workflows/test.yml/badge.svg)](https://github.com/datastack-net/dockerized/actions/workflows/test.yml)
4+
25
Run popular commandline tools without installing them.
36

47
```shell
@@ -9,7 +12,7 @@ dockerized <command>
912

1013
## Supported commands
1114

12-
> If your favorite command is not included, it can be added very easily. See [Add a command](DEV.md).
15+
> If your favorite command is not included, it can be added very easily. See [Customization](#customization).
1316
> Dockerized will also fall back to over 150 commands defined in [jessfraz/dockerfiles](https://github.com/jessfraz/dockerfiles).
1417
1518
- Cloud
@@ -154,7 +157,7 @@ dockerized npm install # install packages.json
154157

155158
## Switching command versions
156159

157-
**Ad-hoc**
160+
### Ad-hoc
158161

159162
Add `:<version>` to the end of the command to override the version.
160163

@@ -163,7 +166,7 @@ dockerized node:15
163166
```
164167

165168

166-
**Listing versions**
169+
### Listing versions
167170

168171
To see which versions are available, run:
169172

@@ -173,7 +176,7 @@ dockerized node:?
173176
dockerized node:
174177
```
175178

176-
**Environment Variables**
179+
### Environment Variables
177180

178181
Each command has a `<COMMAND>_VERSION` environment variable which you can override.
179182

@@ -203,12 +206,12 @@ Notes:
203206
- [.env](.env)
204207

205208

206-
**Per directory**
209+
**Per project (directory)**
207210

208-
You can also specify version and other settings per directory.
211+
You can also specify version and other settings per directory and its subdirectory.
209212
This allows you to "lock" your tools to specific versions for your project.
210213

211-
- Create a `dockerized.env` file in your project directory.
214+
- Create a `dockerized.env` file in the root of your project directory.
212215
- All commands executed within this directory will use the settings specified in this file.
213216

214217

@@ -229,6 +232,111 @@ This allows you to "lock" your tools to specific versions for your project.
229232
dockerized node
230233
```
231234

235+
## Customization
236+
237+
Dockerized uses [Docker Compose](https://docs.docker.com/compose/overview/) to run commands, which are defined in a Compose File.
238+
The default commands are listed in [docker-compose.yml](docker-compose.yml). You can add your own commands or customize the defaults, by loading a custom Compose File.
239+
240+
The `COMPOSE_FILE` environment variable defines which files to load. This variable is set by the included [.env](.env) file, and your own `dockerized.env` files, as explained in [Environment Variables](#environment-variables). To load an additional Compose File, add the path to the file to the `COMPOSE_FILE` environment variable.
241+
242+
243+
### Including an additional Compose File
244+
245+
**Globally**
246+
247+
To change global settings, create a file `dockerized.env` in your home directory, which loads an extra Compose File.
248+
In this example, the Compose File is also in the home directory, referenced relative to the `${HOME}` directory. The original variable `${COMPOSE_FILE}` is included to preserve the default commands. Omit it if you want to completely replace the default commands.
249+
250+
```bash
251+
# ~/dockerized.env
252+
COMPOSE_FILE="${COMPOSE_FILE};${HOME}/docker-compose.yml"
253+
```
254+
255+
```yaml
256+
# ~/docker-compose.yml
257+
```
258+
259+
**Per Project**
260+
261+
To change settings within a specific directory, create a file `dockerized.env` in the root of that directory, which loads the extra Compose File. `${DOCKERIZED_PROJECT_ROOT}` refers to the absolute path to the root of the project.
262+
263+
```shell
264+
# ./dockerized.env
265+
COMPOSE_FILE="${COMPOSE_FILE};${DOCKERIZED_PROJECT_ROOT}/docker-compose.yml"
266+
```
267+
268+
```yaml
269+
# ./docker-compose.yml
270+
```
271+
272+
### Adding custom commands
273+
274+
After adding your custom Compose File to `COMPOSE_FILE`, you can add your own commands.
275+
276+
```yaml
277+
# docker-compose.yml
278+
version: "3"
279+
services:
280+
du:
281+
image: alpine
282+
entrypoint: ["du"]
283+
```
284+
285+
> Now you can run `dockerized du` to see the size of the current directory.
286+
287+
> To learn how to support versioning, see [Development Guide: Configurable Version](DEV.md#configurable-version).
288+
289+
You can also mount a directory to the container:
290+
291+
```yaml
292+
# docker-compose.yml
293+
version: "3"
294+
services:
295+
du:
296+
image: alpine
297+
entrypoint: ["du"]
298+
volumes:
299+
- "${HOME}/.config:/root/.config"
300+
- "${DOCKERIZED_PROJECT_ROOT}/foobar:/foobar"
301+
```
302+
303+
> Make sure host volumes are **absolute paths**. For paths relative to home and the project root, you can use `${HOME}` and `${DOCKERIZED_PROJECT_ROOT}`.
304+
305+
> It is possible to use **relative paths** in the service definitions, but then your Compose File must be loaded **before** the default: `COMPOSE_FILE=${DOCKERIZED_PROJECT_ROOT}/docker-compose.yml;${COMPOSE_FILE}`. All paths are relative to the first Compose File. Compose Files are also merged in the order they are specified, with the last Compose File overriding earlier ones. Because of this, if you want to override the default Compose File, you must load it before _your_ file, and you can't use relative paths.
306+
307+
> To keep **compatibility** with docker-compose, you can specify a default value for `DOCKERIZED_PROJECT_ROOT`, for example: `${DOCKERIZED_PROJECT_ROOT:-.}` sets the default to `.`, allowing you to run like this as well: `docker-compose --rm du -sh /foobar`.
308+
309+
To customize existing commands, you can override or add properties to the `services` section of the Compose File, for the command you want to customize. For example, this is how to set an extra environment variable for `dockerized aws`:
310+
311+
```yaml
312+
# docker-compose.yml
313+
version: "3"
314+
services:
315+
aws:
316+
environment:
317+
AWS_DEFAULT_REGION: "us-east-1"
318+
```
319+
320+
If you'd like to pass environment variables directly from your `dockerized.env` file, you can expose the variable as follows:
321+
322+
```bash
323+
# dockerized.env
324+
AWS_DEFAULT_REGION="us-east-1"
325+
```
326+
327+
```yaml
328+
# docker-compose.yml
329+
version: "3"
330+
services:
331+
aws:
332+
environment:
333+
AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION}"
334+
```
335+
336+
337+
338+
For more information on extending Compose Files, see the Docker Compose documentation: [Multiple Compose Files](https://docs.docker.com/compose/extends/#multiple-compose-files). Note that the `extends` keyword is not supported in the Docker Compose version used by Dockerized.
339+
232340
## Localhost
233341

234342
Dockerized applications run within an isolated network. To access services running on your machine, you need to use `host.docker.internal` instead of `localhost`.

bin/dockerized

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fi
2626
case "$OSTYPE" in
2727
msys | cygwin)
2828
DOCKERIZED_COMPILE_GOOS=windows
29+
DOCKERIZED_BINARY="${DOCKERIZED_BINARY}.exe"
2930
;;
3031
darwin*)
3132
DOCKERIZED_COMPILE_GOOS=darwin
@@ -77,11 +78,11 @@ if [ "$DOCKERIZED_COMPILE" ] || [ ! -f "$DOCKERIZED_BINARY" ]; then
7778
-v "${DOCKERIZED_ROOT}/.cache:/go/pkg" \
7879
-w //src \
7980
"golang:1.17.8" \
80-
build -ldflags "$GO_LDFLAGS" -o //build/ lib/dockerized.go
81+
build -ldflags "$GO_LDFLAGS" -o //build/ .
8182
else
8283
(
8384
cd "$DOCKERIZED_ROOT"
84-
go build -ldflags "$GO_LDFLAGS" -o build/ lib/dockerized.go
85+
go build -ldflags "$GO_LDFLAGS" -o build/ .
8586
)
8687
fi
8788

bin/dockerized.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (($DOCKERIZED_COMPILE -eq $true) -Or !(Test-Path "$DOCKERIZED_BINARY"))
3838
-v "${DOCKERIZED_ROOT}\.cache:/go/pkg" `
3939
-w /src `
4040
"golang:1.17.8" `
41-
build -o /build/ lib/dockerized.go
41+
build -o /build/ .
4242

4343
if ($LASTEXITCODE -ne 0) {
4444
Write-StdErr "Failed to compile dockerized."

docker-compose.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
&alpine
66
image: "alpine_${ALPINE_VERSION}"
77
build:
8-
context: apps/alpine
8+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
99
args:
1010
ALPINE_VERSION: "${ALPINE_VERSION}"
1111
ALPINE_PACKAGES: "tree"
@@ -17,8 +17,9 @@ services:
1717
entrypoint: [ "ansible-playbook" ]
1818
ab:
1919
<<: *alpine
20+
image: "ab"
2021
build:
21-
context: apps/alpine
22+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
2223
args:
2324
ALPINE_VERSION: "${ALPINE_VERSION}"
2425
ALPINE_PACKAGES: "apache2-ssl apache2-utils ca-certificates"
@@ -37,18 +38,18 @@ services:
3738
- "${HOME:-home}/.ssh:/root/.ssh"
3839
- "${HOME:-home}/.dockerized/apps/az:/root/.azure"
3940
bash:
40-
image: "bash"
41+
image: "dockerized_bash"
4142
build:
42-
context: apps/alpine
43+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
4344
args:
4445
ALPINE_VERSION: "${ALPINE_VERSION}"
4546
ALPINE_PACKAGES: "bash"
4647
entrypoint: [ "/bin/bash" ]
4748
doctl:
4849
image: "doctl:${DOCTL_VERSION}"
4950
build:
50-
context: apps/doctl
51-
dockerfile: ../alpine/Dockerfile
51+
context: "${DOCKERIZED_ROOT:-.}/apps/doctl"
52+
dockerfile: "${DOCKERIZED_ROOT:-.}/apps/alpine/Dockerfile"
5253
args:
5354
ALPINE_VERSION: "${ALPINE_VERSION}"
5455
BUILD_SCRIPT_ARGS: "${DOCTL_VERSION}"
@@ -61,16 +62,16 @@ services:
6162
gh:
6263
image: "gh:${GH_VERSION}"
6364
build:
64-
context: apps/gh
65-
dockerfile: ../alpine/Dockerfile
65+
context: "${DOCKERIZED_ROOT:-.}/apps/gh"
66+
dockerfile: "${DOCKERIZED_ROOT:-.}/apps/alpine/Dockerfile"
6667
args:
6768
ALPINE_VERSION: "${ALPINE_VERSION}"
6869
ALPINE_PACKAGES: "git openssh-client"
6970
BUILD_SCRIPT_ARGS: "${GH_VERSION}"
7071
entrypoint: [ "/init.sh", "/gh/bin/gh" ]
7172
volumes:
7273
- "${HOME:-home}/.dockerized/apps/gh:/root"
73-
- "./apps/gh/init.sh:/init.sh"
74+
- "${DOCKERIZED_ROOT:-.}/apps/gh/init.sh:/init.sh"
7475
environment:
7576
BROWSER: "echo"
7677
git:
@@ -100,8 +101,8 @@ services:
100101
pdflatex:
101102
image: "pdflatex"
102103
build:
103-
context: apps/alpine
104-
dockerfile: ../alpine/Dockerfile
104+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
105+
dockerfile: "${DOCKERIZED_ROOT:-.}/apps/alpine/Dockerfile"
105106
args:
106107
ALPINE_VERSION: "${LATEX_ALPINE_VERSION}"
107108
ALPINE_PACKAGES: "texlive-full py-pygments gnuplot make git"
@@ -133,7 +134,7 @@ services:
133134
protoc:
134135
image: "protoc:${PROTOC_VERSION}"
135136
build:
136-
context: apps/protoc
137+
context: "${DOCKERIZED_ROOT:-.}/apps/protoc"
137138
args:
138139
PROTOC_VERSION: "${PROTOC_VERSION}"
139140
PROTOC_BASE: "${PROTOC_BASE}"
@@ -164,7 +165,7 @@ services:
164165
entrypoint: [ "rustc" ]
165166
s3cmd:
166167
build:
167-
context: apps/s3cmd
168+
context: "${DOCKERIZED_ROOT:-.}/apps/s3cmd"
168169
args:
169170
S3CMD_VERSION: "${S3CMD_VERSION}"
170171
S3CMD_BASE: "${S3CMD_BASE}"
@@ -187,15 +188,15 @@ services:
187188
telnet:
188189
<<: *alpine
189190
build:
190-
context: apps/alpine
191+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
191192
args:
192193
ALPINE_VERSION: "${ALPINE_VERSION}"
193194
ALPINE_PACKAGES: "busybox-extras"
194195
entrypoint: [ "telnet" ]
195196
tree:
196197
<<: *alpine
197198
build:
198-
context: apps/alpine
199+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
199200
args:
200201
ALPINE_VERSION: "${ALPINE_VERSION}"
201202
ALPINE_PACKAGES: "tree"
@@ -217,7 +218,7 @@ services:
217218
zip:
218219
image: "zip"
219220
build:
220-
context: apps/alpine
221+
context: "${DOCKERIZED_ROOT:-.}/apps/alpine"
221222
args:
222223
ALPINE_VERSION: "${ALPINE_VERSION}"
223224
ALPINE_PACKAGES: "zip"

dockerized-banner.png

32.6 KB
Loading

0 commit comments

Comments
 (0)