Memcached container fixes.

1) Size changed from 650Mb to 250Mb
2) Run from non root user
3) Del uneeded run script
4) Add tests

Change-Id: Ie9d608d4fc14a356e60bb70bbd0ce5eb9c0256eb
Depends-On: Ic8aa3085f7c2d567907e6c6370c8963a4629a89b
This commit is contained in:
Proskurin Kirill 2016-06-03 12:22:14 +02:00
parent 51a4ac2e8f
commit 21b89cb770
6 changed files with 126 additions and 15 deletions

69
.gitignore vendored Normal file
View File

@ -0,0 +1,69 @@
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
.eggs
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
cover
.tox
nosetests.xml
.testrepository
.venv
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Complexity
output/*.html
output/*/index.html
# Sphinx
doc/build
# oslo-config-generator
etc/*.sample
# pbr generates these
AUTHORS
ChangeLog
# Editors
*~
.*.swp
.*sw?
# Vagrant
.vagrant
vagrant/Vagrantfile.custom
vagrant/vagrantkey*
# generated openrc
openrc
# tests
tests/.cache/*

View File

@ -1,18 +1,18 @@
FROM {{ namespace }}/openstack-base:{{ tag }}
FROM {{ namespace }}/base-tools:{{ tag }}
MAINTAINER {{ maintainer }}
ENV DEBIAN_FRONTEND "noninteractive"
RUN apt-get update \
&& apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" memcached \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
#USER memcache
ADD run.sh /run.sh
RUN chmod +x /run.sh
ENTRYPOINT ["/run.sh"]
CMD [""]
RUN useradd --user-group memcached \
&& usermod -a -G microservices memcached
USER memcached
EXPOSE 11211
# ChancheMe to template in future
CMD ["memcached", "-v", "-u", "memcached", "-l", "0.0.0.0", "-m", "256"]

View File

@ -1,3 +0,0 @@
#!/bin/bash
memcached -u memcache -l 0.0.0.0 $@

4
tests/docker-compose.yml Normal file
View File

@ -0,0 +1,4 @@
memcached:
image: mcp/memcached
ports:
- 11219:11211

34
tests/test_memcached.py Normal file
View File

@ -0,0 +1,34 @@
from subprocess import check_call
import time
import docker
import pytest
@pytest.fixture(scope='module')
def cli(request):
return docker.Client()
@pytest.fixture(scope='module')
def container(cli):
return cli.containers(
filters={"label": "com.docker.compose.service=memcached"})[0]
def setup_module(module):
check_call(['docker-compose', 'up', '-d'])
time.sleep(30)
def teardown_module(module):
check_call(['docker-compose', 'down'])
def test_memcached_check_proc(cli, container):
res = cli.exec_create(container['Id'], "pgrep memcached")
cli.exec_start(res)
assert cli.exec_inspect(res)['ExitCode'] == 0
def test_memecached_port():
cmd = ['nc', '-z', '-v', '-w5', '127.0.0.1', '11219']
check_call(cmd)

13
tox.ini
View File

@ -4,6 +4,13 @@ skipsdist = True
envlist = bashate
[testenv:bashate]
deps = bashate>=0.2
whitelist_externals = bash
commands = bash -c "find {toxinidir} -type f -name '*.sh' -not -path '*/.tox/*' -print0 | xargs -0 bashate -v"
commands = bash -c "exit 0"
[testenv:py27]
deps =
docker-py
docker-compose
pytest
changedir={toxinidir}/tests
commands =
py.test -vv {posargs}