Skip to content

Commit 4234f5f

Browse files
authored
Merge pull request #4 from autopilotpattern/updates
updated ContainerPilot
2 parents 67c2801 + 3037def commit 4234f5f

File tree

4 files changed

+143
-18
lines changed

4 files changed

+143
-18
lines changed

Dockerfile

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,63 @@
1-
FROM memcached:latest
1+
FROM memcached:1.4-alpine
22

3+
# Build-time metadata as defined at http://label-schema.org
4+
# with added usage described in https://microbadger.com/#/labels
5+
ARG BUILD_DATE
6+
ARG VCS_REF
7+
LABEL org.label-schema.build-date=$BUILD_DATE \
8+
org.label-schema.docker.dockerfile="/Dockerfile" \
9+
org.label-schema.name="Autopilot Pattern Memcached" \
10+
org.label-schema.url="https://github.com/autopilotpattern/memcached" \
11+
org.label-schema.vcs-ref=$VCS_REF \
12+
org.label-schema.vcs-type="Git" \
13+
org.label-schema.vcs-url="https://github.com/autopilotpattern/memcached"
14+
15+
# Reset to root user to do some installs
316
USER root
4-
RUN apt-get update \
5-
&& apt-get install -y \
6-
netcat \
7-
curl
817

9-
# Install ContainerPilot
18+
# Install packages
19+
RUN apk update && apk add \
20+
bash \
21+
curl \
22+
netcat-openbsd \
23+
&& rm -rf /var/cache/apk/*
24+
25+
# Add ContainerPilot and its configuration
1026
# Releases at https://github.com/joyent/containerpilot/releases
11-
ENV CONTAINERPILOT_VER 2.0.1
12-
RUN export CONTAINERPILOT_CHECKSUM=a4dd6bc001c82210b5c33ec2aa82d7ce83245154 \
13-
&& curl -Lso /tmp/containerpilot.tar.gz \
14-
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \
27+
ENV CONTAINERPILOT_VER 2.3.0
28+
ENV CONTAINERPILOT file:///etc/containerpilot.json
29+
30+
RUN export CONTAINERPILOT_CHECKSUM=ec9dbedaca9f4a7a50762f50768cbc42879c7208 \
31+
&& curl --retry 7 --fail -Lso /tmp/containerpilot.tar.gz \
32+
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \
1533
&& echo "${CONTAINERPILOT_CHECKSUM} /tmp/containerpilot.tar.gz" | sha1sum -c \
1634
&& tar zxf /tmp/containerpilot.tar.gz -C /usr/local/bin \
1735
&& rm /tmp/containerpilot.tar.gz
1836

19-
# Add ContainerPilot configuration
20-
COPY etc/containerpilot.json /etc/containerpilot.json
21-
ENV CONTAINERPILOT file:///etc/containerpilot.json
37+
# The our helper/glue scripts and configuration for this specific app
38+
COPY bin /usr/local/bin
39+
COPY etc /etc
40+
41+
# Install Consul
42+
# Releases at https://releases.hashicorp.com/consul
43+
RUN export CONSUL_VERSION=0.6.4 \
44+
&& export CONSUL_CHECKSUM=abdf0e1856292468e2c9971420d73b805e93888e006c76324ae39416edcf0627 \
45+
&& curl --retry 7 --fail -vo /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" \
46+
&& echo "${CONSUL_CHECKSUM} /tmp/consul.zip" | sha256sum -c \
47+
&& unzip /tmp/consul -d /usr/local/bin \
48+
&& rm /tmp/consul.zip \
49+
&& mkdir /config
2250

23-
# reset entrypoint from base image
51+
# Create empty directories for Consul config and data
52+
RUN mkdir -p /etc/consul \
53+
&& chown -R memcache /etc/consul \
54+
&& mkdir -p /var/lib/consul \
55+
&& chown -R memcache /var/lib/consul
56+
57+
# Reset entrypoint from base image
2458
ENTRYPOINT []
59+
60+
# Reset to memcache user to, um, run memcache
2561
USER memcache
2662
CMD ["/usr/local/bin/containerpilot", \
2763
"memcached", \

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
[![DockerPulls](https://img.shields.io/docker/pulls/autopilotpattern/memcached.svg)](https://registry.hub.docker.com/u/autopilotpattern/memcached/)
55
[![DockerStars](https://img.shields.io/docker/stars/autopilotpattern/memcached.svg)](https://registry.hub.docker.com/u/autopilotpattern/memcached/)
6-
[![ImageLayers](https://badge.imagelayers.io/autopilotpattern/memcached:latest.svg)](https://imagelayers.io/?images=autopilotpattern/memcached:latest)
7-
[![Join the chat at https://gitter.im/autopilotpattern/general](https://badges.gitter.im/autopilotpattern/general.svg)](https://gitter.im/autopilotpattern/general)
6+
[![MicroBadger version](https://images.microbadger.com/badges/version/autopilotpattern/memcached.svg)](http://microbadger.com/#/images/autopilotpattern/memcached)
7+
[![MicroBadger commit](https://images.microbadger.com/badges/commit/autopilotpattern/memcached.svg)](http://microbadger.com/#/images/autopilotpattern/memcached)
88

99
### Usage
1010
Include this image in your Docker Compose project, query Consul for it's IP address and use it in your configurations, easily done via [Consul-Template](https://github.com/hashicorp/consul-template). The default ContainerPilot configuration talks to Consul and assumes the IP address to access consule is passed to the container in an envrionment varible, $CONSUL
@@ -33,3 +33,12 @@ $memcached_servers = array(
3333
);
3434
{{ end }}
3535
```
36+
37+
### Building
38+
39+
This image implements [microbadger.com](https://microbadger.com/#/labels) label schema, but those labels require additional build args:
40+
41+
```
42+
docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
43+
--build-arg VCS_REF=`git rev-parse --short HEAD` .
44+
```

bin/sensor.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -e
3+
4+
help() {
5+
echo 'Uses cli tools free and top to determine current CPU and memory usage'
6+
echo 'for the telemetry service.'
7+
}
8+
9+
# count of memcached evictions
10+
evictions() {
11+
(>&2 echo "evictions check fired")
12+
local evictions=$(echo -e 'stats\nquit' | nc 127.0.0.1 11211 | awk '/evictions/{print $3}')
13+
echo ${evictions}
14+
}
15+
16+
# memory usage in percent
17+
sys_memory() {
18+
# awk oneliner to get memory usage
19+
# free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
20+
# output:
21+
# Memory Usage: 15804/15959MB (99.03%)
22+
(>&2 echo "sys memory check fired")
23+
local memory=$(free -m | awk 'NR==2{printf "%.2f", $3*100/$2 }')
24+
echo ${memory}
25+
}
26+
27+
# cpu load
28+
sys_cpu() {
29+
# oneliner to display cpu load
30+
# top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
31+
(>&2 echo "sys cpu check fired")
32+
local cpuload=$(top -bn1 | grep load | awk '{printf "%.2f", $(NF-2)}')
33+
echo ${cpuload}
34+
}
35+
36+
cmd=$1
37+
if [ ! -z "$cmd" ]; then
38+
shift 1
39+
$cmd "$@"
40+
exit
41+
fi
42+
43+
help

etc/containerpilot.json

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"consul": "{{ .CONSUL }}:8500",
2+
"consul": "{{ if .CONSUL_AGENT }}localhost{{ else }}{{ .CONSUL }}{{ end }}:8500",
33
"services": [
44
{
55
"name": "memcached",
@@ -8,5 +8,42 @@
88
"poll": 10,
99
"ttl": 25
1010
}
11-
]
11+
],
12+
"coprocesses": [{{ if .CONSUL_AGENT }}
13+
{
14+
"command": ["/usr/local/bin/consul", "agent",
15+
"-data-dir=/var/lib/consul",
16+
"-config-dir=/etc/consul",
17+
"-rejoin",
18+
"-retry-join", "{{ .CONSUL }}",
19+
"-retry-max", "10",
20+
"-retry-interval", "10s"],
21+
"restarts": "unlimited"
22+
}{{ end }}],
23+
"telemetry": {
24+
"port": 9090,
25+
"sensors": [
26+
{
27+
"name": "memcached_evictions",
28+
"help": "count of keys evicted due to memory exhaustion",
29+
"type": "gauge",
30+
"poll": 5,
31+
"check": ["/usr/local/bin/sensor.sh", "evictions"]
32+
},
33+
{
34+
"name": "memcached_sys_memory_percent",
35+
"help": "percentage of memory used",
36+
"type": "gauge",
37+
"poll": 5,
38+
"check": ["/usr/local/bin/sensor.sh", "sys_memory"]
39+
},
40+
{
41+
"name": "memcached_sys_cpu_load",
42+
"help": "cpu load",
43+
"type": "gauge",
44+
"poll": 5,
45+
"check": ["/usr/local/bin/sensor.sh", "sys_cpu"]
46+
}
47+
]
48+
}
1249
}

0 commit comments

Comments
 (0)