Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker images building procedure #42

Merged
merged 9 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 34 additions & 54 deletions .ci/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,44 @@

set -e

DOCKERFILE_PATH="./container"
GIT_REPO_FOLDER="_repo"

# _import_modules
#
# fetch fucntions from the modules folder
function _import_modules
{
for CFILE in $(ls ${ENV_BASH_MODULES_PATH}/*.sh)
do
echo "importing module ${CFILE}"
source ${CFILE} || true
done
}


function _defaults
##
## @brief Changes to the corresponding target and builds the image
##
function _build
{
TARGET=${1:-"dev"}

ENV_MAKE_BUILD=${ENV_MAKE_BUILD:-"true"}
ENV_BASH_MODULES_PATH=${ENV_BASH_MODULES_PATH:-"./modules"}

export ENV_DISTRO=${ENV_DISTRO:-"all"}
export ENV_GIT_PULL_REPO=${ENV_GIT_PULL_REPO:-"true"}
export ENV_DOCKER_IMG=${ENV_DOCKER_IMG:-"wm-gateway"}
export ENV_DOCKER_TAG=${ENV_DOCKER_TAG:-"1.1.0"}
export ENV_DOCKER_CACHE=${ENV_DOCKER_CACHE:-" "}
export ENV_RELEASE_PATH=$(pwd)/release
if [[ ${TARGET} == "dev" ]]
then
_pull_dev_dependencies
fi

export TAR_EXCLUDE_RULES=${TAR_EXCLUDE_RULES:-"$(pwd)/.tarignore"}
export TAR_ARCHIVE_NAME=${TAR_ARCHIVE_NAME:-"docker-wm-gateway.tar.gz"}
cd "${DOCKERFILE_PATH}/${TARGET}"
docker-compose build
}


function _prepare_environment
##
## @brief Setup repo and syncs the repositories
##
function _pull_dev_dependencies
{
# prepares script environment
mkdir -p ${ENV_RELEASE_PATH}
rm -f ${TAR_ARCHIVE_NAME}
GIT_MANIFEST_FILE=${GIT_MANIFEST_FILE:-"gateway.xml"}
GIT_MANIFEST_URL=${GIT_MANIFEST_URL:-"https://github.com/wirepas/manifest.git"}

rm -rf "${GIT_REPO_FOLDER}"
mkdir "${GIT_REPO_FOLDER}"
cd "${GIT_REPO_FOLDER}"
pipenv run --two repo init -u "${GIT_MANIFEST_URL}" \
-m "${GIT_MANIFEST_FILE}" \
--no-clone-bundle
pipenv --rm
pipenv run --two repo sync

cd ..
cp -r "${GIT_REPO_FOLDER}/sink_service/" .
}


Expand All @@ -48,31 +49,10 @@ function _prepare_environment
##
function _main
{
_defaults
_import_modules

lxgw_parser "${@}"

_prepare_environment

if [[ ${ENV_MAKE_BUILD} == "true" ]]
then

if [[ ${ENV_GIT_PULL_REPO} == "true" ]]
then
git_clone_repo "c-mesh-api" "sink_service/c-mesh-api"
git_clone_repo "backend-apis" "public-apis"
else
echo "skipping repo pull"
fi

git_commit_info
lxgw_build_services
fi

lxgw_deliverables
#_build "arm"
#_build "x86"
_build "dev"
}


_main "${@}"

8 changes: 8 additions & 0 deletions .ci/install-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Wirepas Oy

set -e

curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo

chmod a+x /usr/local/bin/repo
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.git
**/*.git
*~
*.o
*.tmp
Expand Down
20 changes: 15 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
language: python
python:
- "3.6"
services:
- docker

dist: "xenial"
jobs:

before_install:
- sudo apt-get install build-essential libsystemd-dev dbus
- pip3 install pipenv

install:
- "./.ci/install-devtools.sh"
- sudo ./.ci/install-repo.sh
- ./.ci/install-devtools.sh
- pip3 install -r dev-requirements.txt
- pip3 install -r python_transport/requirements.txt

script:
- "./.ci/style-check.sh"
- "./.ci/build.sh"
- pip3 install python_transport/dist/*.whl
- ./.ci/style-check.sh
- ./.ci/build.sh
- ./.ci/build-images.sh
- pip3 install python_transport/dist/wirepas_gateway*.whl


deploy:
provider: pypi
Expand All @@ -28,3 +33,8 @@ deploy:
skip_cleanup: true
on:
branch: pypi-test

env:
global:
- PIPENV_VENV_IN_PROJECT=1
- PIPENV_IGNORE_VIRTUALENVS=1
62 changes: 62 additions & 0 deletions container/arm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM wirepas/base:1.1-raspbian as rpi-builder
RUN [ "cross-build-start" ]

ARG GIT_MANIFEST_FILE
ARG GIT_MANIFEST_URL

ENV GIT_MANIFEST_FILE=${GIT_MANIFEST_FILE:-"gateway.xml"}
ENV GIT_MANIFEST_URL=${GIT_MANIFEST_URL:-"https://github.com/wirepas/manifest.git"}

# install git and initialize repo tool
WORKDIR /app_build
RUN apt-get update \
&& apt-get install -y --no-install-recommends git curl python ssh \
&& rm -rf /var/lib/apt/lists/* \
&& curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/bin/repo \
&& chmod a+x /usr/local/bin/repo \
&& repo init -u ${GIT_MANIFEST_URL} \
-m ${GIT_MANIFEST_FILE} \
--no-clone-bundle \
&& repo sync

RUN cd /app_build/sink_service/ \
&& make clean \
&& make

RUN cd /app_build/python_transport/ \
&& ./utils/generate_wheel.sh

RUN [ "cross-build-end" ]

# builds final image
FROM wirepas/base:1.1-raspbian as wm-lxgw
RUN [ "cross-build-start" ]
USER root

ENV SERVICE_HOME="${HOME}/gateway"
ENV SINK_SERVICE="${SERVICE_HOME}/sink_service"
ENV TRANSPORT_SERVICE="${SERVICE_HOME}/transport_service"
ARG WM_TRANSPORT_PKG
ENV WM_TRANSPORT_PKG=${WM_TRANSPORT_PKG:-"${TRANSPORT_SERVICE}/wirepas_gateway-*.tar.gz"}

COPY --from=rpi-builder /app_build/gateway/python_transport/requirements.txt "${TRANSPORT_SERVICE}"/
COPY --from=rpi-builder /app_build/gateway/python_transport/dist/* "${TRANSPORT_SERVICE}"/
COPY --from=rpi-builder /app_build/gateway/python_transport/wirepas_gateway/wirepas_certs/extwirepas.pem /etc/extwirepas.pem
COPY --from=rpi-builder /app_build/gateway/sink_service/build/sinkService /usr/local/bin/sinkService
COPY --from=rpi-builder /app_build/gateway/sink_service/com.wirepas.sink.conf /etc/dbus-1/system.d/

RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r "${TRANSPORT_SERVICE}"/requirements.txt
RUN pip3 install --no-cache-dir ${WM_TRANSPORT_PKG}

RUN rm -rf "${HOME}"/.cache \
&& chown "${USER}":"${USER}" -R "${HOME}"

COPY --from=rpi-builder /app_build/gateway/container/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["sink"]
RUN [ "cross-build-end" ]

ARG LXGW_VERSION
LABEL version=${LXGW_VERSION}
19 changes: 14 additions & 5 deletions container/docker-compose.yml → container/arm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ services:

wm-sink:
container_name: wm-sink
image: wm-gateway:latest
image: wirepas/gateway-rpi
build:
context: ../..
dockerfile: container/arm/Dockerfile
args:
LXGW_VERSION: ${LXGW_VERSION:-"1.2.0-rc.1"}

user: root
privileged: true
Expand All @@ -17,7 +22,7 @@ services:

restart: always
env_file:
- wm_gateway.env
- ../wm_gateway.env

volumes:
- /dev:/dev
Expand All @@ -30,7 +35,12 @@ services:

wm-transport:
container_name: wm-transport
image: wm-gateway:latest
image: wirepas/gateway-rpi
build:
context: ../..
dockerfile: container/arm/Dockerfile
args:
LXGW_VERSION: ${LXGW_VERSION:-"1.2.0-rc.1"}

user: root
privileged: true
Expand All @@ -39,7 +49,7 @@ services:

restart: always
env_file:
- wm_gateway.env
- ../wm_gateway.env
environment:
- PYTHONUNBUFFERED=true

Expand All @@ -50,4 +60,3 @@ services:
driver: journald

command: transport

17 changes: 0 additions & 17 deletions container/build_defaults.env

This file was deleted.

Loading