Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
EOLE
Zéphir
Services
Datasource
Commits
b31f7ca4
Commit
b31f7ca4
authored
Jan 18, 2019
by
Daniel Dehennin
Browse files
Import from all-in-one zephir repository
parent
f806f658
Changes
3
Hide whitespace changes
Inline
Side-by-side
Dockerfile
0 → 100644
View file @
b31f7ca4
####
#### Temporary layer to prepare installation
####
FROM
ubuntu:bionic AS build
# Packages required to build
ENV
DEBIAN_FRONTEND=noninteractive
RUN
apt-get update
-y
&&
apt-get
install
-y
\
curl
\
git
ARG
CONTAINERPILOT_VERSION=3.4.3
ARG
CONTAINERPILOT_CHECKSUM=e8258ed166bcb3de3e06638936dcc2cae32c7c58
RUN
curl
-Lso
/tmp/containerpilot.tar.gz
\
"https://github.com/joyent/containerpilot/releases/download/
${
CONTAINERPILOT_VERSION
}
/containerpilot-
${
CONTAINERPILOT_VERSION
}
.tar.gz"
\
&&
echo
"
${
CONTAINERPILOT_CHECKSUM
}
/tmp/containerpilot.tar.gz"
|
sha1sum
-c
\
&&
tar
zxf /tmp/containerpilot.tar.gz
-C
/tmp
ARG
CONSULTEMPLATE_VERSION=0.19.3
ARG
CONSULTEMPLATE_CHECKSUM=6467b442d8fd68ca0a1eba35f42edb6f3b9941e10b6d58688edc3506fca0bb19
RUN
curl
-Lso
/tmp/consul-template.tar.gz
\
"https://releases.hashicorp.com/consul-template/
${
CONSULTEMPLATE_VERSION
}
/consul-template_
${
CONSULTEMPLATE_VERSION
}
_linux_amd64.tgz"
\
&&
echo
"
${
CONSULTEMPLATE_CHECKSUM
}
/tmp/consul-template.tar.gz"
|
sha256sum
-c
\
&&
tar
zxf /tmp/consul-template.tar.gz
-C
/tmp
# Orcherstration using containerpilot
# Configuration using consul-template
# Use dev-eole repository since gitlab is not public
ARG
CONTAINERPILOT_REPO_URL=https://dev-eole.ac-dijon.fr/git/zephir-orchestrate-containerpilot.git
ARG
CONTAINERPILOT_REPO_REF=223dafd3d093702c8717292247e65d0c55ffb513
RUN
git clone
"
${
CONTAINERPILOT_REPO_URL
}
"
"/tmp/orchestrate"
\
&&
cd
/tmp/orchestrate
\
&&
git checkout
"
${
CONTAINERPILOT_REPO_REF
}
"
# API messages description
# Use dev-eole repository since gitlab is not public
ARG
MESSAGES_API_REPO_URL=https://dev-eole.ac-dijon.fr/git/zephir-messages-api.git
ARG
MESSAGES_API_REPO_REF=e10c743b3a7d1e84ed13bd49a46e7361fd403ccc
RUN
git clone
"
${
MESSAGES_API_REPO_URL
}
"
"/tmp/messages-api"
\
&&
cd
/tmp/messages-api
\
&&
git checkout
"
${
MESSAGES_API_REPO_REF
}
"
# Common python Zéphir library
# Use dev-eole repository since gitlab is not public
ARG
PYTHON_ZEPHIR_REPO_URL=https://dev-eole.ac-dijon.fr/git/python-zephir.git
ARG
PYTHON_ZEPHIR_REPO_REF=bc098b33494c7ef7ae010e130bb773507e196b72
RUN
git clone
"
${
PYTHON_ZEPHIR_REPO_URL
}
"
"/tmp/python-zephir"
\
&&
cd
/tmp/python-zephir
\
&&
git checkout
"
${
PYTHON_ZEPHIR_REPO_REF
}
"
##
## Service specific
##
# EOLE data models
ARG
EOLE_DATA_MODEL_URL=https://dev-eole.ac-dijon.fr/git/zephir-data-model-eole.git
ARG
EOLE_DATA_MODEL_REF=a19f22c50fbdfdd645ebb9d434e8d22860f5bb0d
RUN
git clone
"
${
EOLE_DATA_MODEL_URL
}
"
"/tmp/data-model-eole"
\
&&
cd
/tmp/data-model-eole
\
&&
git checkout
"
${
EOLE_DATA_MODEL_REF
}
"
####
#### Target layer
####
FROM
ubuntu:bionic
MAINTAINER
Pôle EOLE <eole@ac-dijon.fr>
# Packages required for working service
ENV
DEBIAN_FRONTEND=noninteractive
RUN
apt-get update
-y
&&
apt-get
install
-y
\
gnupg
\
jq
\
locales
\
openssl
\
python3
\
python3-aiohttp
\
python3-autobahn
\
python3-dev
\
python3-jwt
\
python3-psycopg2
\
python3-requests
\
python3-yaml
\
sqitch
\
tzdata
# For debug only
RUN
apt-get update
-y
&&
apt-get
install
-y
\
curl
\
iproute2
\
iputils-ping
\
vim
# Force french locale
RUN
locale-gen fr_FR.UTF-8
ENV
LANG fr_FR.UTF-8
ENV
LC_ALL fr_FR.UTF-8
# Force timezone
RUN
ln
-fs
/usr/share/zoneinfo/Europe/Paris /etc/localtime
RUN
dpkg-reconfigure
--frontend
noninteractive tzdata
# Sqitch
RUN
sqitch config
--user
user.name
'Equipe EOLE'
\
&&
sqitch config
--user
user.email
'eole@ac-dijon.fr'
# Install tools from build layer
COPY
--from=build /tmp/containerpilot /usr/local/bin
COPY
--from=build /tmp/consul-template /usr/local/bin
# consul-template wrapper to generate /etc/zephir-services.conf
COPY
--from=build /tmp/orchestrate/update-service-conf /usr/local/bin/
RUN
chmod
+x /usr/local/bin/
*
# Service template for consul-template
ENV
services_conf_filename=zephir-services.conf
ARG
services_conf=/etc/zephir-services.conf
ENV
services_conf=$services_conf
COPY
--from=build /tmp/orchestrate/${services_conf_filename}.ctmpl ${services_conf}.ctmpl
# Install libraries required by service
COPY
--from=build /tmp/python-zephir/zephir /usr/lib/python3/dist-packages/zephir
COPY
--from=build /tmp/messages-api/messages /srv/messages
# Manage container with ContainerPilot
CMD
["/usr/local/bin/containerpilot", "-config", "/etc/containerpilot.json5"]
COPY
containerpilot.json5 /etc/containerpilot.json5
##
## Service specific
##
RUN
apt-get update
-y
&&
apt-get
install
-y
\
mime-support
\
webfs
# Controller
RUN
mkdir
-p
/srv/bin
COPY
scripts/notifier /srv/bin
RUN
chmod
+x /srv/bin/
*
# Install EOLE data models
COPY
--from=build /tmp/data-model-eole/seed /data/seed
# Calcul du hash des fichiers pour que les services puissent vérifier leur état
RUN
cd
/data
&&
find seed
-type
f
-exec
sha256sum
{}
\;
>
SHA256SUMS
&&
sha256sum
SHA256SUMS
>
SHA256SUM
containerpilot.json5
0 → 100644
View file @
b31f7ca4
{
consul: {
address: "{{ .CONSUL_HOST }}"
},
jobs: [
{
name: "datasource",
exec: ["webfsd", "-F", "-R", "/data"],
port: 8000,
health: {
exec: "curl -o /dev/null -s --fail http://localhost:8000/",
ttl: {{ .DATASOURCE_HEALTH_TTL }},
interval: {{ .DATASOURCE_HEALTH_CHECK_INTERVAL }},
}
},
{
name: "datasource-notifier",
exec: ["python3", "-u", "/srv/bin/notifier"],
when: {
source: "watch.crossbar",
once: "healthy"
}
}
],
watches: [
{
name: "crossbar",
interval: 10
}
]
}
scripts/notifier
0 → 100755
View file @
b31f7ca4
# -*- coding: utf-8 -*-
from os import environ
import socket
import asyncio
from autobahn.wamp import subscribe
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
from autobahn.wamp.protocol import Registration, Subscription
class DatasourceNotifier(ApplicationSession):
async def onJoin(self, details):
await self.subscribe(self)
ip = socket.gethostbyname(socket.gethostname())
self.publish(u'v1.zephir.services.event', name='datasource', status='start', ip=ip)
@subscribe('v1.zephir.services.available')
async def is_available(self, *args, name=None, **kwargs):
if name in [None, 'datasource']:
ip = socket.gethostbyname(socket.gethostname())
self.publish(u'v1.zephir.services.event', name='datasource', status='started', ip=ip)
if __name__ == '__main__':
runner = ApplicationRunner(
environ.get("AUTOBAHN_DEMO_ROUTER", u"ws://crossbar:8080/ws"),
u"realm1",
)
runner.run(DatasourceNotifier)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment