├── .gitmodules ├── LICENSE ├── README.md ├── files ├── docker-entrypoint.sh └── gosu ├── provision.yml └── redis.json /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "alexdzyoba.redis"] 2 | path = alexdzyoba.redis 3 | url = https://github.com/alexdzyoba/ansible-redis.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Alex Dzyoba Corp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | redis-packer 2 | ============ 3 | 4 | Packer configuration for building Redis image. 5 | 6 | Described in my post - https://alex.dzyoba.com/blog/packer-for-docker/ 7 | -------------------------------------------------------------------------------- /files/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # first arg is `-f` or `--some-option` 5 | # or first arg is `something.conf` 6 | if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then 7 | set -- redis-server "$@" 8 | fi 9 | 10 | # allow the container to be started with `--user` 11 | if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then 12 | chown -R redis . 13 | exec gosu redis "$0" "$@" 14 | fi 15 | 16 | exec "$@" 17 | -------------------------------------------------------------------------------- /files/gosu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexdzyoba/redis-packer/194c6c91d21851ba4448fc2da2da32f27c71ebdc/files/gosu -------------------------------------------------------------------------------- /provision.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Provision Python 4 | hosts: all 5 | gather_facts: no 6 | tasks: 7 | - name: Boostrap python 8 | raw: test -e /usr/bin/python || (apt-get -y update && apt-get install -y python-minimal) 9 | 10 | - name: Provision Redis 11 | hosts: all 12 | 13 | tasks: 14 | - name: Ensure Redis configured with role 15 | import_role: 16 | name: alexdzyoba.redis 17 | 18 | - name: Create workdir 19 | file: 20 | path: /data 21 | state: directory 22 | owner: root 23 | group: root 24 | mode: 0755 25 | 26 | - name: Put runtime programs 27 | copy: 28 | src: files/{{ item }} 29 | dest: /usr/local/bin/{{ item }} 30 | mode: 0755 31 | owner: root 32 | group: root 33 | with_items: 34 | - gosu 35 | - docker-entrypoint.sh 36 | 37 | - name: Container cleanup 38 | hosts: all 39 | gather_facts: no 40 | tasks: 41 | - name: Remove python 42 | raw: apt-get purge -y python-minimal && apt-get autoremove -y 43 | 44 | - name: Remove apt lists 45 | raw: rm -rf /var/lib/apt/lists/* 46 | -------------------------------------------------------------------------------- /redis.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders": [{ 3 | "type": "docker", 4 | "image": "debian:jessie-slim", 5 | "commit": true, 6 | "changes": [ 7 | "VOLUME /data", 8 | "WORKDIR /data", 9 | "EXPOSE 6379", 10 | "ENTRYPOINT [\"docker-entrypoint.sh\"]", 11 | "CMD [\"redis-server\"]" 12 | ] 13 | }], 14 | 15 | "provisioners": [{ 16 | "type": "ansible", 17 | "user": "root", 18 | "playbook_file": "provision.yml" 19 | }], 20 | 21 | "post-processors": [[ { 22 | "type": "docker-tag", 23 | "repository": "docker.io/alexdzyoba/redis-packer", 24 | "tag": "latest" 25 | } ]] 26 | } 27 | --------------------------------------------------------------------------------