Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wastrachan committed Feb 16, 2020
0 parents commit 50acc14
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: 2
jobs:
build:
environment:
IMAGE_NAME: wastrachan/docker-image-template
docker:
- image: docker:latest
steps:
- checkout
- setup_remote_docker
- run:
name: Install deps
command: |
apk --no-cache add curl
- run:
name: Build image
command: |
docker build -t $IMAGE_NAME:latest .
- deploy:
name: Publish image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
docker push $IMAGE_NAME:latest
fi
- run:
name: Update MicroBadger
command: |
curl -X POST "${MICROBADGER_URL}"
workflows:
version: 2
commit:
jobs:
- build:
filters:
branches:
only: master
nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only: master
jobs:
- build
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# 4 space indentation
[*.sh]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config/
*.img
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:latest
LABEL maintainer="Winston Astrachan"
LABEL description="Software on Alpine Linux"

RUN apk --no-cache add software
RUN mkdir /config

COPY overlay/ /
VOLUME /config
EXPOSE 80/tcp

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/usr/sbin/software", "-c", "/config/named.conf"]
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2019 Winston Astrachan

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Docker Image Makefile
#
# Copyright (c) Winston Astrachan 2019
#
help:
@echo ""
@echo "Usage: make COMMAND"
@echo ""
@echo "Docker Image makefile"
@echo ""
@echo "Commands:"
@echo " build Build and tag image"
@echo " run Start container in the background with locally mounted volume"
@echo " stop Stop and remove container running in the background"
@echo " clean Mark image for rebuild"
@echo " delete Delete image and mark for rebuild"
@echo ""

build: .docker-image-template.img

.docker-image-template.img:
docker build -t wastrachan/docker-image-template:latest .
@touch $@

.PHONY: run
run: build
docker run -v "$(CURDIR)/config:/config" \
--name docker-image-template \
-e PUID=1111 \
-e PGID=1112 \
--restart unless-stopped \
-d \
wastrachan/docker-image-template:latest

.PHONY: stop
stop:
docker stop docker-image-template
docker rm docker-image-template

.PHONY: clean
clean:
rm -f .docker-image-template.img

.PHONY: delete
delete: clean
docker rmi -f wastrachan/docker-image-template
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Docker Image Template
=====================

Software in a Docker container, with configuration files in a volume, and a configurable UID/GID for said files.

[![](https://circleci.com/gh/wastrachan/docker-image-template.svg?style=svg)](https://circleci.com/gh/wastrachan/docker-image-template)
[![](https://images.microbadger.com/badges/image/wastrachan/docker-image-template.svg)](https://microbadger.com/images/wastrachan/docker-image-template)
[![](https://img.shields.io/docker-image-template/pulls/wastrachan/docker-image-template.svg)](https://hub.docker-image-template.com/r/wastrachan/docker-image-template)

## Install

#### Docker Hub
Pull the latest image from Docker Hub:

```shell
docker pull wastrachan/docker-image-template
```

#### Manually
Clone this repository, and run `make build` to build an image:

```shell
git clone https://github.com/wastrachan/docker-image-template.git
cd docker-image-template
make build
```

If you need to rebuild the image, run `make clean build`.


## Run

#### Docker
Run this image with the `make run` shortcut, or manually with `docker run`.


```shell
docker run -v "$(pwd)/config:/config" \
--name image-template \
-e PUID=1111 \
-e PGID=1112 \
--restart unless-stopped \
wastrachan/docker-image-template:latest
```


#### Docker Compose
If you wish to run this image with docker-compose, an example `docker-compose.yml` might read as follows:

```yaml
---
version: "2"

services:
docker-image-template:
image: wastrachan/docker-image-template
container_name: docker-image-template
environment:
- PUID=1111
- PGID=1112
volumes:
- </path/to/config>:/config
ports:
- 80:80/tcp
restart: unless-stopped
```
## Configuration
Configuration files are stored in the `/config` volume. You may wish to mount this volume as a local directory, as shown in the examples above.


#### User / Group Identifiers
If you'd like to override the UID and GID of the application, you can do so with the environment variables `PUID` and `PGID`. This is helpful if other containers must access your configuration volume.

#### Services
Service | Port
------------|-----
HTTP | 80

#### Volumes
Volume | Description
----------------|-------------
`/config` | Configuration directory


## License
The content of this project itself is licensed under the [MIT License](LICENSE).

View license information for the software contained in this image.
2 changes: 2 additions & 0 deletions overlay/defaults/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
template: true
28 changes: 28 additions & 0 deletions overlay/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env sh
set -e

PUID="${PUID:-100}"
PGID="${PGID:-101}"

echo ""
echo "----------------------------------------"
echo " Starting up using the following: "
echo " "
echo " UID: $PUID "
echo " GID: $PGID "
echo "----------------------------------------"
echo ""

# Copy default config files
if [ ! -f "/config/config.yml" ]; then
cp /defaults/config.yml /config/config.yml
fi

# Set UID/GID of software user
sed -i "s/^software\:x\:100\:101/software\:x\:$PUID\:$PGID/" /etc/passwd
sed -i "s/^software\:x\:101/software\:x\:$PGID/" /etc/group

# Set permissions
chown -R $PUID:$PGID /config

exec "$@"

0 comments on commit 50acc14

Please sign in to comment.