chore: config, src and pipelines

This commit is contained in:
Jesús Pérez Lorenzo 2021-08-17 14:15:23 +01:00
parent 75c62e9fe0
commit a8cc48f8f2
11 changed files with 356 additions and 0 deletions

88
src/Dockerfile Normal file
View file

@ -0,0 +1,88 @@
# From https://github.com/nehabhardwaj01/docker-cron
FROM alpine:3.14.1
MAINTAINER Jesús Pérez
ENV RESTIC_VERSION=0.21.1
ENV K8S_VERSION=1.22.0
ENV K8S_ARCH=linux/amd64
ENV JQ_VERSION=1.6
ENV JQ_ARCH=linux64
ENV YQ_VERSION=4.11.2
ENV YQ_ARCH=linux_amd64
ENV RESTIC_ARCH=linux_amd64
ENV SCW_VERSION=2.3.1
ENV SCW_ARCH=linux-amd64
ENV DOCTL_VERSION=1.63.3
ENV DOCTL_ARCH=linux-amd64
ENV AWS_VERSION=1.2022.
ENV AWS_ARCH=linux-amd64
ENV UPCTL_VERSION="1.1.0"
ENV UPCTL_ARCH="linux_x86_64"
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
apt-transport-https \
ca-certificates \
bash \
curl \
apk-cron \
git \
bzip2 \
sed \
supervisor \
fuse \
libressl \
vim \
ssmtp \
zlib \
python3 \
gnupg \
wget \
unzip \
libmagic \
&& update-ca-certificates \
&& python3 -m ensurepip \
&& rm -r /usr/lib/python*/ensurepip \
&& pip3 install --upgrade pip setuptools \
&& if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi \
&& if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi \
&& rm -rf /var/cache/apk/* \
&& pip3 install jinja2 s3cmd awscli \
&& curl -fSL https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/${K8S_ARCH}/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl \
&& curl -fSL https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-${JQ_ARCH} -o /usr/local/bin/jq \
&& chmod +x /usr/local/bin/jq \
&& curl -fSL https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${YQ_ARCH} -o /usr/local/bin/yq \
&& chmod +x /usr/local/bin/yq \
&& curl -fSl https://github.com/scaleway/scaleway-cli/releases/download/v${SCW_VERSION}/scw-${SCW_ARCH} -o /usr/local/bin/scw \
&& chmod +x /usr/local/bin/scw \
&& curl -fSL https://github.com/digitalocean/doctl/releases/download/v${DOCTL_VERSION}/doctl-${DOCTL_VERSION}-${DOCTL_ARCH}.tar.gz -o /usr/local/bin/doctl \
&& chmod +x /usr/local/bin/doctl \
&& wget -q https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_${RESTIC_ARCH}.bz2 -O /tmp/restic-${RESTIC_VERSION}.bz2 \
&& bunzip2 /tmp/restic-${RESTIC_VERSION}.bz2 \
&& mv /tmp/restic-${RESTIC_VERSION} /usr/local/bin/restic \
&& chmod +x /usr/local/bin/restic \
&& rm -f /tmp/restic*
&& echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \
&& curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - \
&& apt-get update -y \
&& apt-get install google-cloud-sdk -y \
&& curl -fSL https://github.com/UpCloudLtd/upcloud-cli/releases/download/v${UPCTL_VERSION}/upcloud-cli_${UPCTL_VERSION}_${UPCTL_ARCH}.tar.gz -o /tmp/upctl.tar.gz \
&& tar xvzCf /usr/local/bin /tmp/upctl.tar.gz upctl \
&& chmod +x /usr/local/bin/upctl \
&& rm -f /tmp/upctl.tar.gz
# Add files
ADD run.sh /usr/local/bin/run.sh
ADD entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/run.sh /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

16
src/entrypoint.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
# from https://blog.knoldus.com/running-a-cron-job-in-docker-container
# Start the run once job.
echo "Container has been started"
declare -p | grep -Ev 'BASHOPTS|BASH_VERSINFO|EUID|PPID|SHELLOPTS|UID' > /container.env
# Setup a cron schedule
echo "SHELL=/bin/bash
BASH_ENV=/container.env
*/5 * * * * /usr/local/bin/run.sh >> /var/log/cron.log 2>&1
# This extra line makes it a valid cron" > scheduler.txt
crontab scheduler.txt
crond -f

3
src/run.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
timestamp=`date +%Y/%m/%d-%H:%M:%S`
echo "System path is $PATH at $timestamp"