From 4a0155dc9d466234b49f6ba507a4b6e0957460d2 Mon Sep 17 00:00:00 2001 From: Carl Sander Date: Thu, 9 Jun 2022 12:18:23 +0200 Subject: [PATCH 1/3] add dir to render command with $0 --- README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.MD b/README.MD index c001e67..ecbeb32 100644 --- a/README.MD +++ b/README.MD @@ -63,7 +63,7 @@ Install needed Tools within Management Container ## create Dockerfile from template with .docker_build configuration ``` bash -sh render.sh +sh render.sh . ``` ## create container image From 3001fae782220a65f40c1bcbbda958ff095b7737 Mon Sep 17 00:00:00 2001 From: Carl Sander Date: Thu, 9 Jun 2022 12:48:37 +0200 Subject: [PATCH 2/3] add help text to render.sh script --- Dockerfile | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++ render.sh | 5 ++ 2 files changed, 195 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..740da03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,190 @@ +###################################### Image ###################################### +ARG ROCKYLINUX_VERSION=8 + +## build Image +FROM rockylinux/rockylinux:${ROCKYLINUX_VERSION} + +# packages to install +RUN yum update -y && \ + yum install -y \ + yum-utils \ + wget \ + jq \ + unzip \ + vim \ + git \ + bash-completion \ + glibc \ + findutils && \ + yum clean all + +################################## Image Config ################################### +ARG PYTHON_VERSION=3 +ARG PACKAGES + +WORKDIR /root + +## python setup +RUN yum install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-pip && \ + yum clean all + +# pip +## upgrade only base packages which are installed by 'yum install python3-pip' +RUN pip3 list -o --format freeze | cut -d'=' -f1 | xargs -n1 pip3 install --upgrade + +## custom packages to install +RUN test -n "${PACKAGES}" && \ + yum install -y ${PACKAGES} && \ + yum clean all || : + +###################################### Tools ###################################### +# define versions +ARG ANSIBLE_VERSION +ARG DOCKER_VERSION +ARG NOMAD_VERSION +ARG CONSUL_VERSION +ARG KUBECTL_VERSION +ARG HELM_VERSION +ARG TERRAFORM_VERSION +ARG AZ_CLI_VERSION +ARG AWS_CLI_VERSION +ARG GCLOUD_VERSION +ARG GITHUB_BINARIES + +WORKDIR /root/download + +## ansible +RUN if [ -n "${ANSIBLE_VERSION}" ] && [ "${ANSIBLE_VERSION}" != "latest" ]; then ANSIBLE="ansible==${ANSIBLE_VERSION}";fi && \ + if [ "${ANSIBLE_VERSION}" == "latest" ]; then ANSIBLE="ansible";fi && \ + test -n "${ANSIBLE_VERSION}" && \ + pip3 install --no-cache-dir ${ANSIBLE} || : + +## docker +RUN if [ -n "${DOCKER_VERSION}" ] && [ "${DOCKER_VERSION}" != "latest" ]; then DOCKER="docker-ce-${DOCKER_VERSION} docker-ce-cli-${DOCKER_VERSION}";fi && \ + if [ "${DOCKER_VERSION}" == "latest" ]; then DOCKER="docker-ce docker-ce-cli";fi && \ + test -n "${DOCKER_VERSION}" && \ + yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && \ + yum install -y ${DOCKER} && \ + yum clean all && \ + systemctl docker start || : + +## nomad +RUN if [ -n "${NOMAD_VERSION}" ] && [ "${NOMAD_VERSION}" != "latest" ]; then NOMAD="nomad-${NOMAD_VERSION}";fi && \ + if [ "${NOMAD_VERSION}" == "latest" ]; then NOMAD="nomad";fi && \ + test -n "${NOMAD_VERSION}" && \ + yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \ + yum install -y ${NOMAD} && \ + yum clean all || : + +## consul +RUN if [ -n "${CONSUL_VERSION}" ] && [ "${CONSUL_VERSION}" != "latest" ]; then CONSUL="consul-${CONSUL_VERSION}";fi && \ + if [ "${CONSUL_VERSION}" == "latest" ]; then CONSUL="consul";fi && \ + test -n "${CONSUL_VERSION}" && \ + yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \ + yum install -y ${CONSUL} && \ + yum clean all || : + +## kubectl +RUN if [ -n "${KUBECTL_VERSION}" ] && [ "${KUBECTL_VERSION}" != "latest" ]; then KUBECTL="kubectl-${KUBECTL_VERSION}";fi && \ + if [ "${KUBECTL_VERSION}" == "latest" ]; then KUBECTL="kubectl";fi && \ + test -n "${KUBECTL_VERSION}" && \ + echo $'[kubernetes] \n\ +name=Kubernetes \n\ +baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 \n\ +enabled=1 \n\ +gpgcheck=1 \n\ +repo_gpgcheck=1 \n\ +gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg \n\ + https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg' > /etc/yum.repos.d/kubernetes.repo && \ + yum install -y ${KUBECTL} && \ + yum clean all && \ + kubectl completion bash > /etc/bash_completion.d/kubectl || : + +## helm +RUN if [ -n "${HELM_VERSION}" ] && [ "${HELM_VERSION}" != "latest" ]; then HELM="v${HELM_VERSION}";fi && \ + if [ "${HELM_VERSION}" == "latest" ]; then HELM="$(curl -sSL https://api.github.com/repos/helm/helm/releases/latest | grep -Po '"tag_name": "\K.*?(?=\")')";fi && \ + test -n "${HELM_VERSION}" && \ + mkdir helm && curl -SsL --retry 5 "https://get.helm.sh/helm-${HELM}-linux-amd64.tar.gz" | tar xz -C ./helm && \ + cp helm/linux-amd64/helm /usr/local/bin/helm && chmod -R +x /usr/local/bin/helm && \ + helm repo add stable https://charts.helm.sh/stable && helm repo update && \ + helm completion bash > /etc/bash_completion.d/helm || : + +## terraform +RUN if [ -n "${TERRAFORM_VERSION}" ] && [ "${TERRAFORM_VERSION}" != "latest" ]; then TERRAFORM="terraform-${TERRAFORM_VERSION}";fi && \ + if [ "${TERRAFORM_VERSION}" == "latest" ]; then TERRAFORM="terraform";fi && \ + test -n "${TERRAFORM_VERSION}" && \ + yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \ + yum install -y ${TERRAFORM} && \ + yum clean all && \ + terraform -install-autocomplete || : + +## az_cli +RUN if [ -n "${AZ_CLI_VERSION}" ] && [ "${AZ_CLI_VERSION}" != "latest" ]; then AZ_CLI="azure-cli-${AZ_CLI_VERSION}";fi && \ + if [ "${AZ_CLI_VERSION}" == "latest" ]; then AZ_CLI="azure-cli";fi && \ + test -n "${AZ_CLI_VERSION}" && \ + rpm --import https://packages.microsoft.com/keys/microsoft.asc && \ + echo $'[azure-cli] \n\ +name=Azure CLI \n\ +baseurl=https://packages.microsoft.com/yumrepos/azure-cli \n\ +enabled=1 \n\ +gpgcheck=1 \n\ +gpgkey=https://packages.microsoft.com/keys/microsoft.asc' > /etc/yum.repos.d/azure-cli.repo && \ + yum install -y ${AZ_CLI} && \ + yum clean all || : + +## aws_cli +RUN if [ -n "${AWS_CLI_VERSION}" ] && [ "${AWS_CLI_VERSION}" != "latest" ]; then AWS_CLI="awscli==${AWS_CLI_VERSION}";fi && \ + if [ "${AWS_CLI_VERSION}" == "latest" ]; then AWS_CLI="awscli";fi && \ + test -n "${AWS_CLI_VERSION}" && \ + pip3 install --no-cache-dir ${AWS_CLI} || : + +## gcloud +RUN if [ -n "${GCLOUD_VERSION}" ] && [ "${GCLOUD_VERSION}" != "latest" ]; then GCLOUD="google-cloud-sdk-${GCLOUD_VERSION}";fi && \ + if [ "${GCLOUD_VERSION}" == "latest" ]; then GCLOUD="google-cloud-sdk";fi && \ + test -n "${GCLOUD_VERSION}" && \ + rpm --import https://packages.microsoft.com/keys/microsoft.asc && \ + echo $'[google-cloud-sdk] \n\ +name=Google Cloud SDK \n\ +baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64 \n\ +enabled=1 \n\ +gpgcheck=1 \n\ +repo_gpgcheck=1 \n\ +gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg \n\ + https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg' > /etc/yum.repos.d/google-cloud-sdk.repo && \ + yum install -y ${GCLOUD} && \ + yum clean all || : + +## github binaries +RUN test -n "${GITHUB_BINARIES}" && \ + for GITHUB_BINARY in ${GITHUB_BINARIES}; do GITHUB_BINARY_NAME=$(echo ${GITHUB_BINARY} | cut -d ':' -f1) && GITHUB_BINARY_VERSION=$(echo ${GITHUB_BINARY} | cut -d ':' -f2) && \ + GITHUB_BINARY_PACKAGE="$(curl -sSL "https://api.github.com/repos/${GITHUB_BINARY_NAME}" | grep -Po '"browser_download_url": "\K.*?(?=\")' | grep "${GITHUB_BINARY_VERSION}.tar.gz")" && \ + mkdir -p ./github && curl -SsL --retry 5 "${GITHUB_BINARY_PACKAGE}" | tar xz -C ./github && \ + chmod -R +x ./github/* && mv ./github/* /usr/local/bin/; done || : + +###################################### Tool Config ################################ +ARG WORKDIR=/root +ARG PIP_REQUIREMENTS +ARG ANSIBLE_REQUIREMENTS +ARG AZ_CLI_EXTENSIONS + +WORKDIR ${WORKDIR} + +## pip +COPY ${PIP_REQUIREMENTS} /tmp/pip_requirements +RUN test -n "${PIP_REQUIREMENTS}" && \ + pip3 install --no-cache-dir -r /tmp/pip_requirements || : + +## ansible-galaxy +COPY ${ANSIBLE_REQUIREMENTS} /tmp/ansible_requirements +RUN test -n "${ANSIBLE_REQUIREMENTS}" && \ + ansible-galaxy collection install -r /tmp/ansible_requirements -p ${WORKDIR}/.ansible/collections/ || : + +## azure cli extension +RUN test -n "${AZ_CLI_EXTENSIONS}" && \ + for AZ_CLI_EXTENSION in ${AZ_CLI_EXTENSIONS}; do az extension add -y --name ${AZ_CLI_EXTENSION}; done || : + +###################################### Config ##################################### +ARG WORKDIR=/root + +WORKDIR ${WORKDIR} +CMD ["/bin/bash"] diff --git a/render.sh b/render.sh index 1bb88e0..aafa044 100644 --- a/render.sh +++ b/render.sh @@ -2,6 +2,11 @@ # generate Dockerfile from template with build settings # init stuff +if [ -n $0 ]; then + printf "no directory provided\n\n" + echo "Usage: sh render.sh " + exit 2 +fi SCRIPT_DIR=$(dirname $(readlink -f $0)) ENV_DIR=${1-SCRIPT_DIR} ENV_FILE="${ENV_DIR}/.docker_build" From 92f6e0e95c110b851f1c72f8db870dde489cf3b1 Mon Sep 17 00:00:00 2001 From: Carl Sander Date: Thu, 9 Jun 2022 13:01:42 +0200 Subject: [PATCH 3/3] Delete Dockerfile --- Dockerfile | 190 ----------------------------------------------------- 1 file changed, 190 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 740da03..0000000 --- a/Dockerfile +++ /dev/null @@ -1,190 +0,0 @@ -###################################### Image ###################################### -ARG ROCKYLINUX_VERSION=8 - -## build Image -FROM rockylinux/rockylinux:${ROCKYLINUX_VERSION} - -# packages to install -RUN yum update -y && \ - yum install -y \ - yum-utils \ - wget \ - jq \ - unzip \ - vim \ - git \ - bash-completion \ - glibc \ - findutils && \ - yum clean all - -################################## Image Config ################################### -ARG PYTHON_VERSION=3 -ARG PACKAGES - -WORKDIR /root - -## python setup -RUN yum install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-pip && \ - yum clean all - -# pip -## upgrade only base packages which are installed by 'yum install python3-pip' -RUN pip3 list -o --format freeze | cut -d'=' -f1 | xargs -n1 pip3 install --upgrade - -## custom packages to install -RUN test -n "${PACKAGES}" && \ - yum install -y ${PACKAGES} && \ - yum clean all || : - -###################################### Tools ###################################### -# define versions -ARG ANSIBLE_VERSION -ARG DOCKER_VERSION -ARG NOMAD_VERSION -ARG CONSUL_VERSION -ARG KUBECTL_VERSION -ARG HELM_VERSION -ARG TERRAFORM_VERSION -ARG AZ_CLI_VERSION -ARG AWS_CLI_VERSION -ARG GCLOUD_VERSION -ARG GITHUB_BINARIES - -WORKDIR /root/download - -## ansible -RUN if [ -n "${ANSIBLE_VERSION}" ] && [ "${ANSIBLE_VERSION}" != "latest" ]; then ANSIBLE="ansible==${ANSIBLE_VERSION}";fi && \ - if [ "${ANSIBLE_VERSION}" == "latest" ]; then ANSIBLE="ansible";fi && \ - test -n "${ANSIBLE_VERSION}" && \ - pip3 install --no-cache-dir ${ANSIBLE} || : - -## docker -RUN if [ -n "${DOCKER_VERSION}" ] && [ "${DOCKER_VERSION}" != "latest" ]; then DOCKER="docker-ce-${DOCKER_VERSION} docker-ce-cli-${DOCKER_VERSION}";fi && \ - if [ "${DOCKER_VERSION}" == "latest" ]; then DOCKER="docker-ce docker-ce-cli";fi && \ - test -n "${DOCKER_VERSION}" && \ - yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && \ - yum install -y ${DOCKER} && \ - yum clean all && \ - systemctl docker start || : - -## nomad -RUN if [ -n "${NOMAD_VERSION}" ] && [ "${NOMAD_VERSION}" != "latest" ]; then NOMAD="nomad-${NOMAD_VERSION}";fi && \ - if [ "${NOMAD_VERSION}" == "latest" ]; then NOMAD="nomad";fi && \ - test -n "${NOMAD_VERSION}" && \ - yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \ - yum install -y ${NOMAD} && \ - yum clean all || : - -## consul -RUN if [ -n "${CONSUL_VERSION}" ] && [ "${CONSUL_VERSION}" != "latest" ]; then CONSUL="consul-${CONSUL_VERSION}";fi && \ - if [ "${CONSUL_VERSION}" == "latest" ]; then CONSUL="consul";fi && \ - test -n "${CONSUL_VERSION}" && \ - yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \ - yum install -y ${CONSUL} && \ - yum clean all || : - -## kubectl -RUN if [ -n "${KUBECTL_VERSION}" ] && [ "${KUBECTL_VERSION}" != "latest" ]; then KUBECTL="kubectl-${KUBECTL_VERSION}";fi && \ - if [ "${KUBECTL_VERSION}" == "latest" ]; then KUBECTL="kubectl";fi && \ - test -n "${KUBECTL_VERSION}" && \ - echo $'[kubernetes] \n\ -name=Kubernetes \n\ -baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 \n\ -enabled=1 \n\ -gpgcheck=1 \n\ -repo_gpgcheck=1 \n\ -gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg \n\ - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg' > /etc/yum.repos.d/kubernetes.repo && \ - yum install -y ${KUBECTL} && \ - yum clean all && \ - kubectl completion bash > /etc/bash_completion.d/kubectl || : - -## helm -RUN if [ -n "${HELM_VERSION}" ] && [ "${HELM_VERSION}" != "latest" ]; then HELM="v${HELM_VERSION}";fi && \ - if [ "${HELM_VERSION}" == "latest" ]; then HELM="$(curl -sSL https://api.github.com/repos/helm/helm/releases/latest | grep -Po '"tag_name": "\K.*?(?=\")')";fi && \ - test -n "${HELM_VERSION}" && \ - mkdir helm && curl -SsL --retry 5 "https://get.helm.sh/helm-${HELM}-linux-amd64.tar.gz" | tar xz -C ./helm && \ - cp helm/linux-amd64/helm /usr/local/bin/helm && chmod -R +x /usr/local/bin/helm && \ - helm repo add stable https://charts.helm.sh/stable && helm repo update && \ - helm completion bash > /etc/bash_completion.d/helm || : - -## terraform -RUN if [ -n "${TERRAFORM_VERSION}" ] && [ "${TERRAFORM_VERSION}" != "latest" ]; then TERRAFORM="terraform-${TERRAFORM_VERSION}";fi && \ - if [ "${TERRAFORM_VERSION}" == "latest" ]; then TERRAFORM="terraform";fi && \ - test -n "${TERRAFORM_VERSION}" && \ - yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \ - yum install -y ${TERRAFORM} && \ - yum clean all && \ - terraform -install-autocomplete || : - -## az_cli -RUN if [ -n "${AZ_CLI_VERSION}" ] && [ "${AZ_CLI_VERSION}" != "latest" ]; then AZ_CLI="azure-cli-${AZ_CLI_VERSION}";fi && \ - if [ "${AZ_CLI_VERSION}" == "latest" ]; then AZ_CLI="azure-cli";fi && \ - test -n "${AZ_CLI_VERSION}" && \ - rpm --import https://packages.microsoft.com/keys/microsoft.asc && \ - echo $'[azure-cli] \n\ -name=Azure CLI \n\ -baseurl=https://packages.microsoft.com/yumrepos/azure-cli \n\ -enabled=1 \n\ -gpgcheck=1 \n\ -gpgkey=https://packages.microsoft.com/keys/microsoft.asc' > /etc/yum.repos.d/azure-cli.repo && \ - yum install -y ${AZ_CLI} && \ - yum clean all || : - -## aws_cli -RUN if [ -n "${AWS_CLI_VERSION}" ] && [ "${AWS_CLI_VERSION}" != "latest" ]; then AWS_CLI="awscli==${AWS_CLI_VERSION}";fi && \ - if [ "${AWS_CLI_VERSION}" == "latest" ]; then AWS_CLI="awscli";fi && \ - test -n "${AWS_CLI_VERSION}" && \ - pip3 install --no-cache-dir ${AWS_CLI} || : - -## gcloud -RUN if [ -n "${GCLOUD_VERSION}" ] && [ "${GCLOUD_VERSION}" != "latest" ]; then GCLOUD="google-cloud-sdk-${GCLOUD_VERSION}";fi && \ - if [ "${GCLOUD_VERSION}" == "latest" ]; then GCLOUD="google-cloud-sdk";fi && \ - test -n "${GCLOUD_VERSION}" && \ - rpm --import https://packages.microsoft.com/keys/microsoft.asc && \ - echo $'[google-cloud-sdk] \n\ -name=Google Cloud SDK \n\ -baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64 \n\ -enabled=1 \n\ -gpgcheck=1 \n\ -repo_gpgcheck=1 \n\ -gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg \n\ - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg' > /etc/yum.repos.d/google-cloud-sdk.repo && \ - yum install -y ${GCLOUD} && \ - yum clean all || : - -## github binaries -RUN test -n "${GITHUB_BINARIES}" && \ - for GITHUB_BINARY in ${GITHUB_BINARIES}; do GITHUB_BINARY_NAME=$(echo ${GITHUB_BINARY} | cut -d ':' -f1) && GITHUB_BINARY_VERSION=$(echo ${GITHUB_BINARY} | cut -d ':' -f2) && \ - GITHUB_BINARY_PACKAGE="$(curl -sSL "https://api.github.com/repos/${GITHUB_BINARY_NAME}" | grep -Po '"browser_download_url": "\K.*?(?=\")' | grep "${GITHUB_BINARY_VERSION}.tar.gz")" && \ - mkdir -p ./github && curl -SsL --retry 5 "${GITHUB_BINARY_PACKAGE}" | tar xz -C ./github && \ - chmod -R +x ./github/* && mv ./github/* /usr/local/bin/; done || : - -###################################### Tool Config ################################ -ARG WORKDIR=/root -ARG PIP_REQUIREMENTS -ARG ANSIBLE_REQUIREMENTS -ARG AZ_CLI_EXTENSIONS - -WORKDIR ${WORKDIR} - -## pip -COPY ${PIP_REQUIREMENTS} /tmp/pip_requirements -RUN test -n "${PIP_REQUIREMENTS}" && \ - pip3 install --no-cache-dir -r /tmp/pip_requirements || : - -## ansible-galaxy -COPY ${ANSIBLE_REQUIREMENTS} /tmp/ansible_requirements -RUN test -n "${ANSIBLE_REQUIREMENTS}" && \ - ansible-galaxy collection install -r /tmp/ansible_requirements -p ${WORKDIR}/.ansible/collections/ || : - -## azure cli extension -RUN test -n "${AZ_CLI_EXTENSIONS}" && \ - for AZ_CLI_EXTENSION in ${AZ_CLI_EXTENSIONS}; do az extension add -y --name ${AZ_CLI_EXTENSION}; done || : - -###################################### Config ##################################### -ARG WORKDIR=/root - -WORKDIR ${WORKDIR} -CMD ["/bin/bash"]