Use install_pakages function in templates

This commit is contained in:
Mikhail Gordeev 2022-12-08 03:47:41 +03:00
parent 0ed27b16b2
commit 4b1472c6e1
20 changed files with 47 additions and 143 deletions

View File

@ -5,6 +5,7 @@ import json
import os
import re
import subprocess
import textwrap
from graphlib import TopologicalSorter
from pathlib import Path
@ -77,6 +78,19 @@ class DockerBuilder:
@forall_images(consume_result=True)
def render_dockerfiles(self, branch, **kwargs):
def install_pakages(*names):
command = f"""
RUN apt-get update && \\
apt-get install -y {' '.join(names)} && \\
rm -f /var/cache/apt/archives/*.rpm \\
/var/cache/apt/*.bin \\
/var/lib/apt/lists/*.*
""".lstrip(
"\n"
)
command = textwrap.dedent(command).rstrip("\n")
return command
if kwargs["dockerfile_template"].exists():
if self.registry:
registry = self.registry.rstrip("/") + "/"
@ -87,6 +101,7 @@ class DockerBuilder:
rendered = Template(kwargs["dockerfile_template"].read_text()).render(
alt_image=alt_image,
branch=branch,
install_pakages=install_pakages,
organization=self.organization,
registry=registry,
)

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y apache2; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("apache2") }}
EXPOSE 80

View File

@ -2,10 +2,6 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y glibc-gconv-modules glibc-locales tzdata; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("glibc-gconv-modules", "glibc-locales", "tzdata") }}
CMD ["bash"]

View File

@ -3,59 +3,27 @@ FROM {{ registry }}{{ organization }}/base:{{ branch }}
MAINTAINER alt-cloud
# install editor
RUN apt-get update && \
apt-get install -y vim-console; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("vim-console") }}
# install debugging tools
RUN apt-get update && \
apt-get install -y strace gdb; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("strace", "gdb") }}
# install document viewers
RUN apt-get update && \
apt-get install -y man; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("man") }}
# install version control system
RUN apt-get update && \
apt-get install -y git-core perl-Git; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("git-core", "perl-Git") }}
# install network utils
RUN apt-get update && \
apt-get install -y curl iproute2; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("iproute2") }}
# install file utils
RUN apt-get update && \
apt-get install -y lsof silver-searcher; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("lsof", "ripgrep") }}
# install shell and completions
RUN apt-get update && \
apt-get install -y zsh zsh-completions; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("zsh", "zsh-completions") }}
# install compilation utils
RUN apt-get update && \
apt-get install -y make gcc gcc-c++; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("make", "gcc", "gcc-c++") }}
CMD ["zsh"]

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y etcd; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("etcd") }}
VOLUME /data

View File

@ -2,17 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y gitea openssh-server; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
RUN apt-get update && \
apt-get install -y gosu; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("gitea", "openssh-server", "gosu") }}
ENV USER gitea
ENV HOME /var/lib/gitea

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y nginx apache2-html tzdata; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("nginx", "apache2-html", "tzdata") }}
RUN cd /etc/nginx/sites-enabled.d && ln -s ../sites-available.d/default.conf .

View File

@ -2,14 +2,11 @@ FROM {{ registry }}{{ organization }}/base:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y python3-module-pip \
python3-module-setuptools \
python3-dev \
gcc \
; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages(
"python3-module-pip",
"python3-module-setuptools",
"python3-dev",
"gcc",
) }}
CMD ["python3"]

View File

@ -2,10 +2,6 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y irb; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("irb") }}
CMD ["irb"]

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ organization }}/base:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y systemd; \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("systemd") }}
RUN ( \
cd /lib/systemd/system/sysinit.target.wants/; \

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y cert-manager && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("cert-manager") }}
RUN groupadd -r -g 1000 cert-manger && useradd --no-log-init -r -u 1000 -g cert-manger cert-manger

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y cert-manager && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("cert-manager") }}
RUN groupadd -r -g 1000 cert-manger && useradd --no-log-init -r -u 1000 -g cert-manger cert-manger

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y cert-manager && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("cert-manager") }}
RUN groupadd -r -g 1000 cert-manger && useradd --no-log-init -r -u 1000 -g cert-manger cert-manger

View File

@ -2,10 +2,6 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y coredns && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("coredns") }}
ENTRYPOINT ["/usr/bin/coredns"]

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y etcd && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("etcd") }}
VOLUME /data

View File

@ -2,10 +2,6 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y kubernetes-master && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("kubernetes-master") }}
ENTRYPOINT ["/usr/bin/kube-apiserver"]

View File

@ -2,10 +2,6 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y kubernetes-master && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("kubernetes-master") }}
ENTRYPOINT ["/usr/bin/kube-controller-manager"]

View File

@ -2,11 +2,7 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y kubernetes-node && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("kubernetes-node") }}
RUN ln -s /usr/bin/kube-proxy /usr/local/bin/kube-proxy

View File

@ -2,10 +2,6 @@ FROM {{ registry }}{{ alt_image }}:{{ branch }}
MAINTAINER alt-cloud
RUN apt-get update && \
apt-get install -y kubernetes-master && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("kubernetes-master") }}
ENTRYPOINT ["/usr/bin/kube-scheduler"]

View File

@ -1,12 +1,6 @@
FROM alt:sisyphus as installer
FROM {{ registry }}{{ alt_image }}:{{ branch }}
RUN apt-get update && \
apt-get install -y apt-repo && \
sh -c 'yes | apt-repo test 310153' && \
apt-get remove -y apt-repo && \
rm -f /var/cache/apt/archives/*.rpm \
/var/cache/apt/*.bin \
/var/lib/apt/lists/*.*
{{ install_pakages("kubernetes-pause") }}
FROM scratch