Skip to content

Commit

Permalink
Rebuild using docker-template v1.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed Apr 1, 2020
1 parent 6de1371 commit b9f91c7
Show file tree
Hide file tree
Showing 29 changed files with 387 additions and 225 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*/logs/*.log
.*.swp
*.OLD
docker-template
Expand Down
Empty file removed 1.0.0/logs/.keep
Empty file.
Binary file removed 1.0.0/logs/mailhog.log
Binary file not shown.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ endif

################################################################################
# Image related commands.
.DEFAULT:
@make -k help

default: all

all:
Expand All @@ -65,6 +68,8 @@ all:
help:
@echo "################################################################################"
@echo "init - Initialize repository from TEMPLATE."
@echo "update - Update repository TEMPLATE."
@echo "git-release - Generate a repository release."
@echo ""
@echo "clean-[all | <VERSION>] - Clean runtime container image."
@echo "build-[all | <VERSION>] - Generate runtime container image."
Expand Down Expand Up @@ -102,6 +107,15 @@ init: *.json
@./bin/create-version.sh "all"


################################################################################
update:
@./bin/TemplateUpdate.sh
@make init

git-release:
@./bin/TemplateRelease.sh


################################################################################
info:
@./bin/$@.sh $(VERSION)
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Gearbox](https://github.com/gearboxworks/gearbox.github.io/raw/master/Gearbox-100x.png)
![Gearbox](https://raw.githubusercontent.com/gearboxworks/gearboxworks.github.io/master/assets/images/gearbox-logo.png)


# Another [Gearbox](https://github.com/gearboxworks/) Docker container service - mailhog
# mailhog Docker container service for [Gearbox](https://github.com/gearboxworks/)
This is the repository for the [mailhog](https://github.com/mailhog/MailHog) Docker container implemented for [Gearbox](https://github.com/gearboxworks/).


Expand All @@ -12,10 +12,9 @@ GitHub release(latest): ![last-release-date](https://img.shields.io/github/relea


## Supported versions and respective Dockerfiles
| Service | GitHub Version | Docker Version | Docker Size | Docker Tags | Dockerfile |
| ------- | -------------- | -------------- | ----------- | ----------- | ---------- |
| [mailhog](https://github.com/mailhog/MailHog) | ![mailhog](https://img.shields.io/badge/mailhog-1.0.0-green.svg) | ![Docker Version)](https://img.shields.io/docker/v/gearboxworks/mailhog/1.0.0) | ![Docker Size](https://img.shields.io/docker/image-size/gearboxworks/mailhog/1.0.0) | `1.0.0`, `1.0`, `latest` | _([1.0.0/DockerfileRuntime](https://github.com/gearboxworks/docker-mailhog/blob/master/1.0/DockerfileRuntime))_ |

| Service | GitHub Version | Docker Version | Docker Size | Docker Tags |
| ------- | -------------- | -------------- | ----------- | ----------- |
| [mailhog](https://github.com/mailhog/MailHog) | ![mailhog](https://img.shields.io/badge/mailhog-1.0.0-green.svg) | ![Docker Version)](https://img.shields.io/docker/v/gearboxworks/mailhog/1.0.0) | ![Docker Size](https://img.shields.io/docker/image-size/gearboxworks/mailhog/1.0.0) | _([`1.0.0`, `1.0`, `latest`](https://github.com/gearboxworks/docker-mailhog/blob/master/1.0/DockerfileRuntime))_ |


## Using this container.
Expand All @@ -42,7 +41,7 @@ Simply clone this repository to your local machine
`make push` - Push already built Docker images to Docker Hub, (only for Gearbox admins). Push all versions from the base directory or specific versions from each directory.

### Runtime from GitHub repo
When you `cd` into a version directory you can also perform a few more actions.
You can either build your container as above, or use it from DockerHub with these commands:

`make start` - Spin up a Docker container with the correct runtime configs.

Expand Down
14 changes: 14 additions & 0 deletions TEMPLATE/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ endif

################################################################################
# Image related commands.
.DEFAULT:
@make -k help

default: all

all:
Expand All @@ -65,6 +68,8 @@ all:
help:
@echo "################################################################################"
@echo "init - Initialize repository from TEMPLATE."
@echo "update - Update repository TEMPLATE."
@echo "git-release - Generate a repository release."
@echo ""
@echo "clean-[all | <VERSION>] - Clean runtime container image."
@echo "build-[all | <VERSION>] - Generate runtime container image."
Expand Down Expand Up @@ -102,6 +107,15 @@ init: *.json
@./bin/create-version.sh "all"


################################################################################
update:
@./bin/TemplateUpdate.sh
@make init

git-release:
@./bin/TemplateRelease.sh


################################################################################
info:
@./bin/$@.sh $(VERSION)
Expand Down
38 changes: 21 additions & 17 deletions TEMPLATE/README.md.tmpl
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
![Gearbox](https://github.com/gearboxworks/gearbox.github.io/raw/master/Gearbox-100x.png)
![Gearbox](https://raw.githubusercontent.com/gearboxworks/gearboxworks.github.io/master/assets/images/gearbox-logo.png)


# Another [Gearbox](https://github.com/gearboxworks/) Docker container service - {{ .Json.name }}
This is the repository for the [{{ .Json.name }}]({{ .Json.refurl }}) Docker container implemented for [Gearbox](https://github.com/gearboxworks/).
# {{ .Json.meta.name }} Docker container service for [Gearbox](https://github.com/gearboxworks/)
This is the repository for the [{{ .Json.meta.name }}]({{ .Json.meta.refurl }}) Docker container implemented for [Gearbox](https://github.com/gearboxworks/).


## Repository Info
GitHub commit: ![commit-date](https://img.shields.io/github/last-commit/gearboxworks/docker-{{ .Json.name }}?style=flat-square)
GitHub commit: ![commit-date](https://img.shields.io/github/last-commit/gearboxworks/docker-{{ .Json.meta.name }}?style=flat-square)

GitHub release(latest): ![last-release-date](https://img.shields.io/github/release-date/gearboxworks/docker-{{ .Json.name }}) ![last-release-date](https://img.shields.io/github/v/tag/gearboxworks/docker-{{ .Json.name }}?sort=semver) [![release-state](https://github.com/gearboxworks/docker-{{ .Json.name }}/workflows/release/badge.svg?event=release)](https://github.com/gearboxworks/docker-{{ .Json.name }}/actions?query=workflow%3Arelease)
GitHub release(latest): ![last-release-date](https://img.shields.io/github/release-date/gearboxworks/docker-{{ .Json.meta.name }}) ![last-release-date](https://img.shields.io/github/v/tag/gearboxworks/docker-{{ .Json.meta.name }}?sort=semver) [![release-state](https://github.com/gearboxworks/docker-{{ .Json.meta.name }}/workflows/release/badge.svg?event=release)](https://github.com/gearboxworks/docker-{{ .Json.meta.name }}/actions?query=workflow%3Arelease)


## Supported versions and respective Dockerfiles
{{- if .Json.base }}
{{- if .Json.build.base }}
| Base | GitHub Version | Docker Version | Docker Size | Docker Tags |
| ------- | -------------- | -------------- | ----------- | ----------- |
{{- range $key, $value := .Json.versions }}
| {{ if $.Json.refurl }}[{{ $.Json.name }}]({{ $.Json.refurl }}){{ else }}{{ $.Json.name }}{{ end }} | ![{{ $.Json.name }}](https://img.shields.io/badge/{{ $key }}-green.svg) | ![Docker Version)](https://img.shields.io/docker/v/gearboxworks/{{ $.Json.name }}/{{ $key }}) | ![Docker Size](https://img.shields.io/docker/image-size/gearboxworks/{{ $.Json.name }}/{{ $key }}) | _([`{{ $key }}`{{ with $value.majorversion }}, `{{ . }}`{{ end }}{{ with $value.latest }}, `latest`{{ end }}](https://github.com/gearboxworks/docker-{{ $.Json.name }}/blob/master/{{ $value.majorversion }}/DockerfileRuntime))_ |
{{- if ne $key "" }}
| {{ if $.Json.meta.refurl }}[{{ $.Json.meta.name }}]({{ $.Json.meta.refurl }}){{ else }}{{ $.Json.meta.name }}{{ end }} | ![{{ $.Json.meta.name }}](https://img.shields.io/badge/{{ $key }}-green.svg) | ![Docker Version)](https://img.shields.io/docker/v/gearboxworks/{{ $.Json.meta.name }}/{{ $key }}) | ![Docker Size](https://img.shields.io/docker/image-size/gearboxworks/{{ $.Json.meta.name }}/{{ $key }}) | _([`{{ $key }}`{{ with $value.majorversion }}, `{{ . }}`{{ end }}{{ with $value.latest }}, `latest`{{ end }}](https://github.com/gearboxworks/docker-{{ $.Json.meta.name }}/blob/master/{{ $value.majorversion }}/DockerfileRuntime))_ |
{{- end }}
{{- end }}
{{- else }}
| Service | GitHub Version | Docker Version | Docker Size | Docker Tags |
| ------- | -------------- | -------------- | ----------- | ----------- |
{{- range $key, $value := .Json.versions }}
| {{ if $.Json.refurl }}[{{ $.Json.name }}]({{ $.Json.refurl }}){{ else }}{{ $.Json.name }}{{ end }} | ![{{ $.Json.name }}](https://img.shields.io/badge/{{ $.Json.name }}-{{ $key }}-green.svg) | ![Docker Version)](https://img.shields.io/docker/v/gearboxworks/{{ $.Json.name }}/{{ $key }}) | ![Docker Size](https://img.shields.io/docker/image-size/gearboxworks/{{ $.Json.name }}/{{ $key }}) | _([`{{ $key }}`{{ with $value.majorversion }}, `{{ . }}`{{ end }}{{ with $value.latest }}, `latest`{{ end }}](https://github.com/gearboxworks/docker-{{ $.Json.name }}/blob/master/{{ $value.majorversion }}/DockerfileRuntime))_ |
{{- if ne $key "" }}
| {{ if $.Json.meta.refurl }}[{{ $.Json.meta.name }}]({{ $.Json.meta.refurl }}){{ else }}{{ $.Json.meta.name }}{{ end }} | ![{{ $.Json.meta.name }}](https://img.shields.io/badge/{{ $.Json.meta.name }}-{{ $key }}-green.svg) | ![Docker Version)](https://img.shields.io/docker/v/gearboxworks/{{ $.Json.meta.name }}/{{ $key }}) | ![Docker Size](https://img.shields.io/docker/image-size/gearboxworks/{{ $.Json.meta.name }}/{{ $key }}) | _([`{{ $key }}`{{ with $value.majorversion }}, `{{ . }}`{{ end }}{{ with $value.latest }}, `latest`{{ end }}](https://github.com/gearboxworks/docker-{{ $.Json.meta.name }}/blob/master/{{ $value.majorversion }}/DockerfileRuntime))_ |
{{- end }}
{{- end }}
{{- end }}

Expand All @@ -39,7 +43,7 @@ You can either use it directly from DockerHub or GitHub.
### Setup from GitHub repo
Simply clone this repository to your local machine

`git clone https://github.com/gearboxworks/{{ .Json.name }}-docker.git`
`git clone https://github.com/gearboxworks/{{ .Json.meta.name }}-docker.git`

### Building from GitHub repo
`make build` - Build Docker images. Build all versions from the base directory or specific versions from each directory.
Expand All @@ -51,7 +55,7 @@ Simply clone this repository to your local machine
`make push` - Push already built Docker images to Docker Hub, (only for Gearbox admins). Push all versions from the base directory or specific versions from each directory.

### Runtime from GitHub repo
When you `cd` into a version directory you can also perform a few more actions.
You can either build your container as above, or use it from DockerHub with these commands:

`make start` - Spin up a Docker container with the correct runtime configs.

Expand All @@ -69,38 +73,38 @@ When you `cd` into a version directory you can also perform a few more actions.
## Method 2: Docker Hub

### Setup from Docker Hub
A simple `docker pull gearbox/{{ .Json.name }}` will pull down the latest version.
A simple `docker pull gearbox/{{ .Json.meta.name }}` will pull down the latest version.

### Starting
start - Spin up a Docker container with the correct runtime configs.

`docker run -d --name {{ .Json.name }}-latest --restart unless-stopped --network gearboxnet gearbox/{{ .Json.name }}:latest`
`docker run -d --name {{ .Json.meta.name }}-latest --restart unless-stopped --network gearboxnet gearbox/{{ .Json.meta.name }}:latest`

### Stopping
stop - Stop a Docker container.

`docker stop {{ .Json.name }}-latest`
`docker stop {{ .Json.meta.name }}-latest`

### Remove container
rm - Remove the Docker container.

`docker container rm {{ .Json.name }}-latest`
`docker container rm {{ .Json.meta.name }}-latest`

### Run in foreground
run - Run a Docker container in the foreground, (all STDOUT and STDERR will go to console). The Container be removed on termination.

`docker run --rm --name {{ .Json.name }}-latest --network gearboxnet gearbox/{{ .Json.name }}:latest`
`docker run --rm --name {{ .Json.meta.name }}-latest --network gearboxnet gearbox/{{ .Json.meta.name }}:latest`

### Run a shell
shell - Run a shell, (/bin/bash), within a Docker container.

`docker run --rm --name {{ .Json.name }}-latest -i -t --network gearboxnet gearbox/{{ .Json.name }}:latest /bin/bash`
`docker run --rm --name {{ .Json.meta.name }}-latest -i -t --network gearboxnet gearbox/{{ .Json.meta.name }}:latest /bin/bash`

### SSH
ssh - All [Gearbox](https://github.com/gearboxworks/) containers have a running SSH daemon. So you can connect remotely.

```
SSH_PORT="$(docker port {{ .Json.name }}-latest 22/tcp | sed 's/0.0.0.0://')"
SSH_PORT="$(docker port {{ .Json.meta.name }}-latest 22/tcp | sed 's/0.0.0.0://')"
ssh -p ${SSH_PORT} -o StrictHostKeyChecking=no gearbox@localhost
```

20 changes: 13 additions & 7 deletions TEMPLATE/build.sh.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# {{ .CreationWarning }}
# {{ .CreationInfo }}
{{ if not .Json.name }}
{{ if not .Json.meta.name }}
# No name

{{ else }}
Expand All @@ -26,24 +26,30 @@ else
fi

################################################################################
if [ -f "{{ .JsonFile.Dir }}/{{ .JsonFile.Name }}" ]
then
cp "{{ .JsonFile.Dir }}/{{ .JsonFile.Name }}" "${DIR}/gearbox-{{ .Json.name }}.json"
fi
#if [ -f "{{ .JsonFile.Dir }}/{{ .JsonFile.Name }}" ]
#then
# if [ "${GB_REF}" == "base" ]
# then
# cp "{{ .JsonFile.Dir }}/{{ .JsonFile.Name }}" "${DIR}/{{ .Json.meta.name }}.json"
# else
# cp "{{ .JsonFile.Dir }}/{{ .JsonFile.Name }}" "${DIR}/gearbox-{{ .Json.meta.name }}.json"
# fi
# cp "{{ .JsonFile.Dir }}/{{ .JsonFile.Name }}" "${DIR}/gearbox.json"
#fi

################################################################################
TMPLDIRS="$(find ${DIR}/ -name '*JSON_NAME*')"
for dir in ${TMPLDIRS}
do
NEWDIR="$(echo -n "${dir}" | sed 's/JSON_NAME/{{ .Json.name }}/')"
NEWDIR="$(echo -n "${dir}" | sed 's/JSON_NAME/{{ .Json.meta.name }}/')"
mv -i "${dir}" "${NEWDIR}"
done

################################################################################
TMPLFILES="$(find ${DIR}/ -name '*\.tmpl')"
for file in ${TMPLFILES}
do
OUTFILE="$(echo -n "${file}" | sed 's/JSON_NAME/{{ .Json.name }}/')"
OUTFILE="$(echo -n "${file}" | sed 's/JSON_NAME/{{ .Json.meta.name }}/')"
if [ "${file}" != "${OUTFILE}" ]
then
mv -i "${file}" "${OUTFILE}"
Expand Down
14 changes: 8 additions & 6 deletions TEMPLATE/build/build/JSON_NAME.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ c_ok "Started."
c_ok "Installing packages."
APKBIN="$(which apk)"
if [ "${APKBIN}" != "" ]
if [ -f /etc/gearbox/build/{{ .Json.name }}.apks ]
then
if [ -f /etc/gearbox/build/{{ .Json.meta.name }}.apks ]
then
APKS="$(cat /etc/gearbox/build/{{ .Json.name }}.apks)"
APKS="$(cat /etc/gearbox/build/{{ .Json.meta.name }}.apks)"
${APKBIN} update && ${APKBIN} add --no-cache ${APKS}; checkExit
fi
fi

APTBIN="$(which apt-get)"
if [ "${APTBIN}" != "" ]
if [ -f /etc/gearbox/build/{{ .Json.name }}.apt ]
then
if [ -f /etc/gearbox/build/{{ .Json.meta.name }}.apt ]
then
DEBS="$(cat /etc/gearbox/build/{{ .Json.name }}.apt)"
DEBS="$(cat /etc/gearbox/build/{{ .Json.meta.name }}.apt)"
${APTBIN} update && ${APTBIN} install ${DEBS}; checkExit
fi
fi


if [ -f /etc/gearbox/build/{{ .Json.name }}.env ]
if [ -f /etc/gearbox/build/{{ .Json.meta.name }}.env ]
then
. /etc/gearbox/build/{{ .Json.name }}.env
. /etc/gearbox/build/{{ .Json.meta.name }}.env
fi

if [ ! -d /usr/local/bin ]
Expand Down
4 changes: 2 additions & 2 deletions TEMPLATE/build/unit-tests/JSON_NAME/01-base.sh.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# {{ .CreationInfo }}

p_info "{{ .Json.name }}" "Release test started."
p_info "{{ .Json.meta.name }}" "Release test started."

if id -u gearbox
then
Expand All @@ -17,5 +17,5 @@ else
c_err "Gearbox group NOT found."
fi

p_info "{{ .Json.name }}" "Release test finished."
p_info "{{ .Json.meta.name }}" "Release test finished."

35 changes: 17 additions & 18 deletions TEMPLATE/version.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,48 @@
{{ if not $version }}
# No version found in gearbox.json

{{ else if not .Json.name }}
{{ else if not .Json.meta.name }}
# No name found in gearbox.json

{{ else }}
VERSION="{{ .Env.GB_VERSION }}"
export VERSION

if [ -d "${VERSION}" ]
GB_VERDIR="versions/{{ .Env.GB_VERSION }}"
export GB_VERDIR

if [ -d "${GB_VERDIR}" ]
then
echo "Gearbox: Release version directory ${VERSION} already exists."
echo "Gearbox: Release version directory ${GB_VERDIR} already exists."
exit 1
fi

################################################################################
# Maybe we have rsync, maybe we don't.
mkdir "${VERSION}"
mkdir -p "${GB_VERDIR}"
mkdir -p "${GB_VERDIR}/logs"

RSYNC="$(which rsync)"
if [ "${RSYNC}" != "" ]
then
rsync -HvaxP TEMPLATE/version/ "${VERSION}/"
rsync -HvaxP TEMPLATE/version/ "${GB_VERDIR}/"
else
tar cf - -C TEMPLATE/version . | tar xvf - -C "${VERSION}"
fi

################################################################################
if [ -f "{{ $.JsonFile.Dir }}/{{ $.JsonFile.Name }}" ]
then
cp "{{ $.JsonFile.Dir }}/{{ $.JsonFile.Name }}" "${VERSION}/gearbox.json"
tar cf - -C TEMPLATE/version . | tar xvf - -C "${GB_VERDIR}"
fi

################################################################################
TMPLDIRS="$(find ${VERSION}/ -name '*JSON_NAME*')"
TMPLDIRS="$(find ${GB_VERDIR}/ -name '*JSON_NAME*')"
for dir in ${TMPLDIRS}
do
NEWDIR="$(echo -n "${dir}" | sed 's/JSON_NAME/{{ $.Json.name }}/')"
NEWDIR="$(echo -n "${dir}" | sed 's/JSON_NAME/{{ $.Json.meta.name }}/')"
mv -i "${dir}" "${NEWDIR}"
done

################################################################################
TMPLFILES="$(find ${VERSION}/ -name '*\.tmpl')"
TMPLFILES="$(find ${GB_VERDIR}/ -name '*\.tmpl')"
for file in ${TMPLFILES}
do
OUTFILE="$(echo -n "${file}" | sed 's/JSON_NAME/{{ $.Json.name }}/')"
OUTFILE="$(echo -n "${file}" | sed 's/JSON_NAME/{{ $.Json.meta.name }}/')"
if [ "${file}" != "${OUTFILE}" ]
then
mv -i "${file}" "${OUTFILE}"
Expand All @@ -58,7 +56,8 @@ do
{{ $.ExecName }} -json "{{ $.JsonFile.Dir }}/{{ $.JsonFile.Name }}" -create "${OUTFILE}"
done

find ${VERSION}/rootfs/etc/gearbox/services -type f | xargs chmod 755
find ${VERSION}/ -name '*\.sh' | xargs chmod 755
find ${GB_VERDIR}/rootfs/etc/gearbox/services -type f | xargs chmod 755
find ${GB_VERDIR}/ -name '*\.sh' | xargs chmod 755

{{ end }}
# END
Loading

0 comments on commit b9f91c7

Please sign in to comment.