Commit a401c02c authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

alpine based image. multistage builds for debian image

parent 83203d64
.idea/* .idea/
noc_tower.egg-info/ noc_tower.egg-info/
build/ build/
dist/ dist/
root/ root/
var/* var/
pip-selfcheck.json pip-selfcheck.json
local/** local/**
lib/* lib/
include/* include/
bin/* share/
share/*
*.pyc *.pyc
.idea/ .idea/
include/ include/
lib/ lib/
Would skip repository local/
share/ share/
var/ var/
\ No newline at end of file
...@@ -42,7 +42,7 @@ upload: ...@@ -42,7 +42,7 @@ upload:
- tags - tags
build_image: build_image:
stage: build_image stage: build_image_debian
before_script: before_script:
- export VERSION=$(cat VERSION) - export VERSION=$(cat VERSION)
- export CONTAINER_NAME=$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME - export CONTAINER_NAME=$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
...@@ -56,6 +56,25 @@ build_image: ...@@ -56,6 +56,25 @@ build_image:
- build_tgz - build_tgz
tags: tags:
- shell - shell
only:
- master
- tags
build_image:
stage: build_image_alpine
before_script:
- export VERSION=$(cat VERSION)
- export CONTAINER_NAME=$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME_alpine
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker build --pull --build-arg="http_proxy=$PROXY" --build-arg="https_proxy=$PROXY" --build-arg=VERSION=${VERSION} -t $CONTAINER_NAME .
- docker push $CONTAINER_NAME
- if [ -n "${CI_BUILD_TAG}" ]; then docker tag $CONTAINER_NAME $CI_REGISTRY_IMAGE:${CI_BUILD_TAG}_alpine; docker push $CI_REGISTRY_IMAGE:${CI_BUILD_TAG}; fi
- if [ -n "${CI_BUILD_TAG}" ]; then docker tag $CONTAINER_NAME $CI_REGISTRY_IMAGE:alpine; docker push $CI_REGISTRY_IMAGE:latest; fi
dependencies:
- build_tgz
tags:
- shell
only: only:
- master - master
- tags - tags
\ No newline at end of file
FROM debian:latest FROM python:2.7 as builder
RUN mkdir /mnt/tower
WORKDIR /mnt/tower/
COPY . /mnt/tower/
RUN python setup.py sdist --format=zip
WORKDIR /opt/tower
RUN virtualenv /opt/tower && ./bin/pip install /mnt/tower/dist/*.zip
FROM debian:latest as app
ENV PATH /opt/tower/bin:${PATH} ENV PATH /opt/tower/bin:${PATH}
ENV ANSIBLE_HOST_KEY_CHECKING=False \ ENV ANSIBLE_HOST_KEY_CHECKING=False \
ANSIBLE_SSH_PIPELINING=1 \ ANSIBLE_SSH_PIPELINING=1 \
ANSIBLE_STDOUT_CALLBACK=debug \ ANSIBLE_STDOUT_CALLBACK=debug \
PYTHONUNBUFFERED=1 \ PYTHONUNBUFFERED=1 \
VERSION=${VERSION} VERSION=${VERSION} \
PYTHONPATH=/opt/tower/lib/python2.7:/usr/lib/python2.7
COPY --from=builder /opt/tower /opt/tower
# install systemv packages # install systemv packages
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
python-virtualenv \ libpython2.7 \
libffi-dev \ libpython2.7-stdlib \
python-dev gcc \ libpython-stdlib \
python2.7 \
python-minimal \
ca-certificates \
openssh-client \ openssh-client \
libssl-dev \
vim-tiny \
sqlite3 \
curl \
telnet \
git \
&& rm -rf /var/cache/apk/* \ && rm -rf /var/cache/apk/* \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/*
&& python /usr/lib/python2.7/dist-packages/virtualenv.py /opt/tower \
&& /opt/tower/bin/pip install https://cdn.getnoc.com/tower/noc-tower-latest.zip \
&& apt-get -y purge gcc libssl-dev libffi-dev
WORKDIR /opt/tower WORKDIR /opt/tower
......
FROM alpine:3.6 as builder
RUN mkdir /mnt/tower
WORKDIR /mnt/tower/
COPY . /mnt/tower/
RUN apk add --update py2-cffi py-virtualenv gcc python-dev musl-dev libffi-dev openssl-dev ca-certificates
RUN python setup.py sdist --format=zip
WORKDIR /opt/tower
RUN virtualenv /opt/tower && ./bin/pip install /mnt/tower/dist/*.zip
FROM python:2.7-alpine3.6 FROM python:2.7-alpine3.6
ENV ANSIBLE_HOST_KEY_CHECKING=False \ ENV ANSIBLE_HOST_KEY_CHECKING=False \
ANSIBLE_SSH_PIPELINING=1 \ ANSIBLE_SSH_PIPELINING=1 \
ANSIBLE_STDOUT_CALLBACK=debug \ ANSIBLE_STDOUT_CALLBACK=debug \
PYTHONUNBUFFERED=1 \ PYTHONUNBUFFERED=1 \
VERSION=${VERSION} VERSION=${VERSION} \
PYTHONPATH=/opt/tower/lib/python2.7/site-packages/:/usr/local/lib/python2.7:/usr/local/lib/python2.7/site-packages
COPY --from=builder /opt/tower /opt/tower
# install systemv packages # install systemv packages
RUN apk add --update ca-certificates openssh-client vim sqlite curl git libffi-dev gcc musl-dev openssl-dev libffi\ RUN apk add --update ca-certificates openssh-client vim sqlite curl git libffi
&& mkdir -p /opt/tower \
&& pip install https://cdn.getnoc.com/tower/noc-tower-latest.zip \
&& apk del libffi-dev gcc musl-dev openssl-dev
WORKDIR /usr/local/ WORKDIR /opt/tower
COPY entrypoint-alpine.sh / COPY entrypoint.sh /
STOPSIGNAL SIGINT STOPSIGNAL SIGINT
ENTRYPOINT ["/entrypoint-alpine.sh"] ENTRYPOINT ["/entrypoint.sh"]
VOLUME /usr/local/var/tower/ VOLUME /opt/tower/var/
EXPOSE 8888 EXPOSE 8888
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
set -xe set -xe
if [ ! -f /usr/local/var/tower/data/deploy_keys/id_rsa ]; then if [ ! -f /opt/tower/var/tower/data/deploy_keys/id_rsa ]; then
mkdir -p /usr/local/var/tower/data/deploy_keys mkdir -p /opt/tower/var/tower/data/deploy_keys
ssh-keygen -t rsa -b 4096 -f /usr/local/var/tower/data/deploy_keys/id_rsa ssh-keygen -t rsa -b 4096 -f /opt/tower/var/tower/data/deploy_keys/id_rsa
chmod 0700 /usr/local/var/tower/data/deploy_keys/ chmod 0700 /opt/tower/var/tower/data/deploy_keys/
cd /usr/local cd /opt/tower
mkdir -p /usr/local/var/tower/db /usr/local/var/tower/cache /usr/local/var/tower/repo mkdir -p /opt/tower/var/tower/db /opt/tower/var/tower/cache /opt/tower/var/tower/repo
mkdir -p /usr/local/var/tower/log/jobs /usr/local/var/tower/log/crashinfo/collect mkdir -p /opt/tower/var/tower/log/jobs /opt/tower/var/tower/log/crashinfo/collect
mkdir -p /usr/local/var/tower/ansible/cp /usr/local/var/tower/crashinfo mkdir -p /opt/tower/var/tower/ansible/cp /opt/tower/var/tower/crashinfo
mkdir -p /usr/local/var/tower/data/src_dist/ mkdir -p /opt/tower/var/tower/data/src_dist/
fi fi
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment