Skip to content
Open
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
54 changes: 54 additions & 0 deletions docker-containers/microservice_jammy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM docker.io/ubuntu:22.04
MAINTAINER Cerebro <cerebro@ganymede.eu>

ENV LANG='C.UTF-8' LC_ALL='C.UTF-8'
ENV DISTRIB_CODENAME=jammy DISTRIB_RELEASE=22.04
ENV CONFIG_DIR config

ENV MICROSERVICE_VERSION 2.11.3

# Set up container's timezone
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get install -y tzdata

#--- Install common utils ---
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
apt-utils \
bash-completion \
cron \
curl \
file \
gcc \
git \
iproute2 \
less \
mc \
nano \
net-tools \
netcat \
python3 \
python3-dev \
python3-pip \
sudo \
software-properties-common \
supervisor \
unzip \
vim \
wget \
haproxy

#--- Install armada ---
COPY ./armada-microservice_${MICROSERVICE_VERSION}_amd64.deb /tmp/armada-microservice_${MICROSERVICE_VERSION}_amd64.deb
RUN dpkg -i /tmp/armada-microservice_${MICROSERVICE_VERSION}_amd64.deb || true
RUN apt-get install -y --fix-broken --no-install-recommends
RUN dpkg -l armada-microservice

#--- Cleanup ---
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

#--- Add python alias ---
RUN ln -s /usr/bin/python3 /usr/bin/python

CMD ["microservice", "bootstrap"]
18 changes: 18 additions & 0 deletions docker-containers/microservice_jammy/build_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e
set -x

SERVICE_NAME=microservice_packaging

#workdir to file directory
cd "$(dirname "${BASH_SOURCE[0]}")"

PACKAGE_VERSION=$1
if [[ ! -n ${PACKAGE_VERSION} ]]; then
PACKAGE_VERSION=$(grep 'ENV MICROSERVICE_VERSION' Dockerfile | awk '{ print $3 }' | tr -d '[[:space:]]')
fi

docker build --rm -t "${SERVICE_NAME}" -f packaging/Dockerfile ./packaging
docker run --rm -t -v "$(pwd)/packaging:/opt/microservice" "${SERVICE_NAME}" --version="${PACKAGE_VERSION}"

mv -f "$(pwd)/packaging/armada-microservice_${PACKAGE_VERSION}_amd64.deb" "$(pwd)/"
30 changes: 30 additions & 0 deletions docker-containers/microservice_jammy/packaging/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM docker.io/ubuntu:22.04

# Set up container's timezone
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get install -y tzdata

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
build-essential \
g++ \
gcc \
git \
libc6-dev \
libffi-dev \
make \
python3 \
rpm \
ruby \
ruby-dev \
rubygems

# Install package builder
RUN gem install fpm

COPY package_build.py /usr/bin/package_build
RUN chmod +x /usr/bin/package_build

WORKDIR "/opt/microservice"
VOLUME "/opt/microservice"
ENTRYPOINT ["/usr/bin/package_build"]
5 changes: 5 additions & 0 deletions docker-containers/microservice_jammy/packaging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Microservice packaging

# Building

```./build_package.sh <version number>```
19 changes: 19 additions & 0 deletions docker-containers/microservice_jammy/packaging/after-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -ex

sudo -H python3 -m pip install --upgrade pip setuptools
sudo -H python3 -m pip install --upgrade web.py

mkdir -p /var/log/supervisor /var/opt/service-registration/
ln -sf /opt/microservice/microservice /opt/microservice/src

echo VERSION = \"<%= version %>\" > /opt/microservice/microservice/version.py

sudo -H python3 -m pip install --upgrade /opt/microservice

chmod +x /opt/microservice/scripts/* /opt/microservice/src/run_hooks.py

grep 'source /opt/microservice/scripts/tools/microservice_bashrc.source' /etc/bash.bashrc || {
echo "source /opt/microservice/scripts/tools/microservice_bashrc.source" >> /etc/bash.bashrc
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sed -i '/source \/opt\/microservice\/scripts\/tools\/microservice_bashrc.source/d' /etc/bash.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_acd_action() {

local command="acd"

local current=${COMP_WORDS[COMP_CWORD]}
local previous=${COMP_WORDS[COMP_CWORD-1]}

if [[ "$previous" == "$command" ]]; then
COMPREPLY=($(compgen -W "$(find /opt/${IMAGE_NAME}/* -type d -printf "%f\n")" -- $current))
fi

return 0
}

complete -F _acd_action acd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_atail_action() {

local command="atail"

local current=${COMP_WORDS[COMP_CWORD]}
local previous=${COMP_WORDS[COMP_CWORD-1]}

if [[ "$previous" == "$command" ]]; then
COMPREPLY=($(compgen -W "$(find /var/log/supervisor/* -printf "%f\n")" -- $current))
fi

return 0
}

complete -F _atail_action atail
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
_supervisorctl_action() {

local service_options=(start restart stop status tail pid reload reread update)
local generic_options=(avail maintail shutdown)
local all_options=($(echo ${service_options[@]}) $(echo ${generic_options[@]}))
local command=("supervisorctl" "actl")

local current=${COMP_WORDS[COMP_CWORD]}
local previous=${COMP_WORDS[COMP_CWORD-1]}

if [[ "${all_options[@]}" =~ "$current" && "${command[@]}" =~ $previous ]]; then
COMPREPLY=($(compgen -W "$(echo ${all_options[@]})" -- $current) )
fi

if [[ "${service_options[@]}" =~ "$previous" ]]; then
COMPREPLY=($(compgen -W "$(supervisorctl status | awk '{print $1}')" -- $current) )
fi

return 0
}

complete -F _supervisorctl_action supervisorctl
complete -F _supervisorctl_action actl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[program:armada_agent]
command=microservice agent
stdout_logfile_maxbytes=5MB
stdout_logfile_backups=2
stderr_logfile_maxbytes=5MB
stderr_logfile_backups=2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[program:local_magellan]
command=microservice local-magellan
exitcodes=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[program:register_in_service_discovery]
command=microservice register 80
startsecs=0
priority=10
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[program:require]
command=microservice require -c service_discovery.json
startsecs=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[supervisord]
nodaemon=true
user=root

[inet_http_server]
port = 127.0.0.1:9001
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

body=$(curl -s localhost/health)

if [ "${body,,}" == "ok" ]; then # ",," is to make ${body} lowercase
echo "HTTP health check OK"
exit 0
fi
echo "HTTP health check failed"
exit 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

check_interface() {
if [[ "${port}" == */udp ]]; then
# -v is necessary, otherwise nc always returns 0 for UDP ports.
nc -z -u -v $1 $(cut -d/ -f1 <<< ${port})
else
nc -z $1 ${port}
fi
}

port=80
if [ -n "$1" ]; then
port="$1"
fi

ips=$( ip address | awk '/inet/&&!/inet6/{split($2,a,"/");print a[1]}' )

for ip in ${ips}; do
check_interface ${ip}

if [ $? -eq 0 ]; then
exit 0
fi
done

exit 2
Loading