From 479fba0ae677c82b24ce8a22339af348dca85464 Mon Sep 17 00:00:00 2001 From: "rancococ@qq.com" Date: Wed, 15 May 2019 13:04:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- centos/Dockerfile | 76 ------------- centos/build.sh | 141 ------------------------ centos/docker-entrypoint.sh | 26 ----- centos/run.sh | 54 --------- {alpine => docker}/Dockerfile | 0 {alpine => docker}/build.sh | 0 {alpine => docker}/docker-entrypoint.sh | 0 {alpine => docker}/run.sh | 0 8 files changed, 297 deletions(-) delete mode 100644 centos/Dockerfile delete mode 100644 centos/build.sh delete mode 100644 centos/docker-entrypoint.sh delete mode 100644 centos/run.sh rename {alpine => docker}/Dockerfile (100%) rename {alpine => docker}/build.sh (100%) rename {alpine => docker}/docker-entrypoint.sh (100%) rename {alpine => docker}/run.sh (100%) diff --git a/centos/Dockerfile b/centos/Dockerfile deleted file mode 100644 index ebda928..0000000 --- a/centos/Dockerfile +++ /dev/null @@ -1,76 +0,0 @@ -# from registry.cn-hangzhou.aliyuncs.com/rancococ/centos:7-utf8 -FROM registry.cn-hangzhou.aliyuncs.com/rancococ/centos:7-utf8 - -# maintainer -MAINTAINER "rancococ" - -# set arg info -ARG CENTOS_VER=7 -ARG APP_HOME=/data/app -ARG JRE_HOME=/data/jre -ARG GOSU_URL=https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64 -ARG JRE_URL=https://github.com/rancococ/serverjre/releases/download/server-jre-8/server-jre-8u192-linux-x64.tar.gz - -# copy script -COPY docker-entrypoint.sh / - -# install repositories and packages : curl bash passwd openssl openssh wget net-tools gettext zip unzip ncurses -RUN \rm -rf /etc/yum.repos.d/*.repo && \ - curl -s -o /etc/yum.repos.d/centos.repo http://mirrors.aliyun.com/repo/Centos-${CENTOS_VER}.repo && \ - curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-${CENTOS_VER}.repo && \ - sed -i '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/centos.repo && \ - sed -i '/mirrors.cloud.aliyuncs.com/d' /etc/yum.repos.d/centos.repo && \ - yum clean all && yum makecache && \ - \rm -rf /etc/pki/rpm-gpg/* && \ - curl -s -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-${CENTOS_VER} https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-${CENTOS_VER} && \ - curl -s -o /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-${CENTOS_VER} https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-${CENTOS_VER} && \ - rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-${CENTOS_VER} && \ - rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-${CENTOS_VER} && \ - sed -i 's@override_install_langs=en_US.utf8@#override_install_langs=en_US.utf8@g' "/etc/yum.conf" && \ - yum install -y passwd openssl openssh-server wget net-tools gettext zip unzip ncurses && \ - yum reinstall -y glibc-common && \ - yum clean all && \rm -rf /var/lib/{cache,log} /var/log/lastlog && \ - ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' && \ - ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' && \ - ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N '' && \ - sed -i 's/#UseDNS.*/UseDNS no/g' /etc/ssh/sshd_config && \ - sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^/#/' /etc/pam.d/sshd && \ - echo "Asia/Shanghai" > /etc/timezone && \ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh && echo 'admin' | passwd --stdin root && \ - mkdir -p ${APP_HOME} && mkdir -p ${JRE_HOME} && \ - groupadd -r app && useradd -r -m -g app -d ${APP_HOME} -s /bin/bash app && echo '123456' | passwd --stdin app && \ - tempuuid=$(cat /proc/sys/kernel/random/uuid) && mkdir -p /tmp/${tempuuid} && \ - wget -c -O /usr/local/bin/gosu --no-cookies --no-check-certificate "${GOSU_URL}" && chmod +x /usr/local/bin/gosu && \ - wget -c -O /tmp/${tempuuid}/myjre.tar.gz --no-cookies --no-check-certificate ${JRE_URL} && \ - myjrename=$(tar -tzf /tmp/${tempuuid}/myjre.tar.gz | awk -F "/" '{print $1}' | sed -n '1p') && \ - tar -xzf /tmp/${tempuuid}/myjre.tar.gz -C ${JRE_HOME} --strip-components=2 ${myjrename}/jre && \ - \rm -rf /tmp/${tempuuid} && \ - sed -i 's@securerandom.source=file:/dev/random@securerandom.source=file:/dev/urandom@g' "${JRE_HOME}/lib/security/java.security" && \ - sed -i 's@#crypto.policy=unlimited@crypto.policy=unlimited@g' "${JRE_HOME}/lib/security/java.security" && \ - chmod -Rf u+x ${JRE_HOME}/bin/* && \ - chown -R app:app /data && \ - chown -R app:app /docker-entrypoint.sh && \ - chmod +x /docker-entrypoint.sh - -# set environment -ENV LANG zh_CN.UTF-8 -ENV TZ "Asia/Shanghai" -ENV TERM xterm -ENV JAVA_HOME ${JRE_HOME} -ENV CLASSPATH .:${JRE_HOME}/lib -ENV PATH .:${PATH}:${JRE_HOME}/bin - -# set work home -WORKDIR /data - -# expose port 22 -EXPOSE 22 - -# stop signal -STOPSIGNAL SIGTERM - -# entry point -ENTRYPOINT ["/docker-entrypoint.sh"] - -# default command -CMD ["java", "-version"] diff --git a/centos/build.sh b/centos/build.sh deleted file mode 100644 index cbd233b..0000000 --- a/centos/build.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o noglob - -# -# font and color -# -bold=$(tput bold) -underline=$(tput sgr 0 1) -reset=$(tput sgr0) - -red=$(tput setaf 1) -green=$(tput setaf 2) -yellow=$(tput setaf 3) -blue=$(tput setaf 4) -white=$(tput setaf 7) - -# -# header and logging -# -header() { printf "\n${underline}${bold}${blue}> %s${reset}\n" "$@"; } -header2() { printf "\n${underline}${bold}${blue}>> %s${reset}\n" "$@"; } -info() { printf "${white}➜ %s${reset}\n" "$@"; } -warn() { printf "${yellow}➜ %s${reset}\n" "$@"; } -error() { printf "${red}✖ %s${reset}\n" "$@"; } -success() { printf "${green}✔ %s${reset}\n" "$@"; } -usage() { printf "\n${underline}${bold}${blue}Usage:${reset} ${blue}%s${reset}\n" "$@"; } - -trap "error '******* ERROR: Something went wrong.*******'; exit 1" sigterm -trap "error '******* Caught sigint signal. Stopping...*******'; exit 2" sigint - -set +o noglob - -# -# entry base dir -# -pwd=`pwd` -base_dir="${pwd}" -source="$0" -while [ -h "$source" ]; do - base_dir="$( cd -P "$( dirname "$source" )" && pwd )" - source="$(readlink "$source")" - [[ $source != /* ]] && source="$base_dir/$source" -done -base_dir="$( cd -P "$( dirname "$source" )" && pwd )" -cd ${base_dir} - -# registry -registry_host="registry.cn-hangzhou.aliyuncs.com" -registry_username="rancococ@qq.com" -registry_password="" - -# images -images=( -java:1.8.192-centos,registry.cn-hangzhou.aliyuncs.com/rancococ/java:1.8-centos -java:1.8.192-centos,registry.cn-hangzhou.aliyuncs.com/rancococ/java:1.8.192-centos -) - -# build image -fun_build_image() { -docker build --rm \ - --no-cache \ - --add-host github.com:192.30.253.112 \ - --add-host github.com:192.30.253.113 \ - --add-host codeload.github.com:192.30.253.120 \ - --add-host codeload.github.com:192.30.253.121 \ - --add-host assets-cdn.github.com:151.101.72.133 \ - --add-host assets-cdn.github.com:151.101.76.133 \ - --add-host github.global.ssl.fastly.net:151.101.73.194 \ - --add-host github.global.ssl.fastly.net:151.101.77.194 \ - --add-host raw.githubusercontent.com:151.101.72.133 \ - --add-host raw.githubusercontent.com:151.101.228.133 \ - --add-host s3.amazonaws.com:52.216.100.205 \ - --add-host s3.amazonaws.com:52.216.130.69 \ - --add-host github-cloud.s3.amazonaws.com:52.216.64.104 \ - --add-host github-cloud.s3.amazonaws.com:52.216.166.91 \ - --add-host github-production-release-asset-2e65be.s3.amazonaws.com:54.231.114.66 \ - --add-host github-production-release-asset-2e65be.s3.amazonaws.com:52.216.165.147 \ - --build-arg GOSU_URL=https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64 \ - --build-arg JRE_URL=https://github.com/rancococ/serverjre/releases/download/server-jre-8/server-jre-8u192-linux-x64.tar.gz \ - -t java:1.8.192-centos \ - -f Dockerfile . -} - -# login registry -fun_login_registry() { - header "login registry : ${registry_host}" - info "Please enter your password for [${registry_username}]:" - read -s registry_password - if [ "x${registry_password}" == "x" ]; then - error "Please enter you password." - exit 0 - fi - echo "${registry_password}" | docker login --username="${registry_username}" --password-stdin "${registry_host}" - return 0 -} - -# push image -fun_push_image() { - header "push images to registry : ${registry_host}" - for data in ${images[@]}; do - source=${data%%,*} - target=${data#*,} - info "push image [${target}] start..."; - docker tag ${source} ${target} - docker push ${target} - success "push image [${target}] success." - done - return 0 -} - -# clean images -fun_clean_images() { - header "clean images:" - none_images=$(docker images -f "dangling=true" -q) - if [ "x${none_images}" != "x" ]; then - docker rmi -f $(docker images -f "dangling=true" -q); - fi - success "clean image success." - return 0 -} - -# -# main -# -# login registry -fun_login_registry - -# build image -fun_build_image - -# push image -fun_push_image - -# clean images -fun_clean_images - -success "build image complete." - -exit $? diff --git a/centos/docker-entrypoint.sh b/centos/docker-entrypoint.sh deleted file mode 100644 index 1223cca..0000000 --- a/centos/docker-entrypoint.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -# exec docker-preprocess.sh -if [ -x "/docker-preprocess.sh" ]; then - . "/docker-preprocess.sh" -fi - -# current user is root -if [ "$(id -u)" = "0" ]; then - # no parameter - if [ -z "$1" ]; then - # exec default command - exec /bin/sh -c "/usr/sbin/sshd -D" - fi - # has parameter - if [ -n "$1" ]; then - # exec by app - exec gosu app "$@" - fi -fi - -# current user is not root -# exec by spec user -exec "$@" diff --git a/centos/run.sh b/centos/run.sh deleted file mode 100644 index f97c980..0000000 --- a/centos/run.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o noglob - -# -# font and color -# -bold=$(tput bold) -underline=$(tput sgr 0 1) -reset=$(tput sgr0) - -red=$(tput setaf 1) -green=$(tput setaf 2) -yellow=$(tput setaf 3) -blue=$(tput setaf 4) -white=$(tput setaf 7) - -# -# header and logging -# -header() { printf "\n${underline}${bold}${blue}> %s${reset}\n" "$@"; } -header2() { printf "\n${underline}${bold}${blue}>> %s${reset}\n" "$@"; } -info() { printf "${white}➜ %s${reset}\n" "$@"; } -warn() { printf "${yellow}➜ %s${reset}\n" "$@"; } -error() { printf "${red}✖ %s${reset}\n" "$@"; } -success() { printf "${green}✔ %s${reset}\n" "$@"; } -usage() { printf "\n${underline}${bold}${blue}Usage:${reset} ${blue}%s${reset}\n" "$@"; } - -trap "error '******* ERROR: Something went wrong.*******'; exit 1" sigterm -trap "error '******* Caught sigint signal. Stopping...*******'; exit 2" sigint - -set +o noglob - -# -# entry base dir -# -pwd=`pwd` -base_dir="${pwd}" -source="$0" -while [ -h "$source" ]; do - base_dir="$( cd -P "$( dirname "$source" )" && pwd )" - source="$(readlink "$source")" - [[ $source != /* ]] && source="$base_dir/$source" -done -base_dir="$( cd -P "$( dirname "$source" )" && pwd )" -cd ${base_dir} - -# run default command -docker run -it --rm --name java-1.8.192-centos java:1.8.192-centos -# run sshd -docker run -it --rm --name java-1.8.192-centos -p 10022:22 java:1.8.192-centos "" -# run bash -docker run -it --rm --name java-1.8.192-centos -p 18080:8080 -p 10001:10001 -p 10002:10002 java:1.8.192-centos "bash" diff --git a/alpine/Dockerfile b/docker/Dockerfile similarity index 100% rename from alpine/Dockerfile rename to docker/Dockerfile diff --git a/alpine/build.sh b/docker/build.sh similarity index 100% rename from alpine/build.sh rename to docker/build.sh diff --git a/alpine/docker-entrypoint.sh b/docker/docker-entrypoint.sh similarity index 100% rename from alpine/docker-entrypoint.sh rename to docker/docker-entrypoint.sh diff --git a/alpine/run.sh b/docker/run.sh similarity index 100% rename from alpine/run.sh rename to docker/run.sh