Refactor again (#11)

This commit is contained in:
Ryan (hackercat)
2021-05-28 11:31:42 +00:00
committed by GitHub
parent da6b7b185b
commit 6ffb01cfd3
21 changed files with 461 additions and 236 deletions
+24 -18
View File
@@ -1,22 +1,26 @@
ARG BASEIMAGE=buildpack-deps
ARG IMAGE=buildpack-deps
ARG TAG=20.04
FROM ${BASEIMAGE}:${TAG}
FROM ${IMAGE}:${TAG}
# > automatic buildx ARGs
ARG TARGETARCH
ARG TARGETVARIANT
# > ARGs before FROM are not accessible
ARG BASEIMAGE=buildpack-deps
ARG IMAGE=buildpack-deps
ARG TAG=20.04
# > Node version
# > NodeJS version
ARG NODE_VERSION=12
# > Force apt to not be interactive/not ask
ARG DEBIAN_FRONTEND=noninteractive
SHELL [ "/bin/bash", "--login", "-o", "pipefail", "-c" ]
SHELL [ "/bin/bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c" ]
# > setup environment required for GitHub Actions
RUN set -Eeuxo pipefail \
&& printf "Build started\n" \
&& printf "\n\n\t🐋\t Build started \t🐋\t\n\n" \
&& echo "USER=$(whoami)" | tee -a /etc/environment \
&& echo "RUNNER_USER=$(whoami)" | tee -a /etc/environment \
&& ImageOS=ubuntu$(echo ${TAG} | cut -d'.' -f 1) \
@@ -34,44 +38,46 @@ RUN set -Eeuxo pipefail \
&& mkdir -p /github \
&& chown 1000:1000 /github \
&& chmod 0777 /github \
&& printf "Installing packages\n\n" \
&& printf "\n\n\t🐋\t Installing packages \t🐋\t\n\n" \
&& apt-get -yq update \
&& printf "Updated apt lists and upgraded packages\n\n" \
&& apt-get -yq install --no-install-recommends ssh lsb-release gawk jq curl git wget sudo gnupg-agent ca-certificates software-properties-common apt-transport-https libyaml-0-2 zstd unzip xz-utils "$(apt-cache search libicu | grep -E 'libicu[[:digit:]]+ -' | cut -d \" \" -f 1)" \
&& ln -s $(which python3) /usr/local/bin/python \
&& [[ "${TAG}" == "16.04" ]] && printf 'git-lfs not available for Xenial' || apt-get -yq install --no-install-recommends git-lfs \
&& printf "Creating ~/.ssh and adding 'github.com'\n\n" \
&& printf "\n\n\t🐋\t Updated apt lists and upgraded packages \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Creating ~/.ssh and adding 'github.com' \t🐋\t\n\n" \
&& mkdir -p ~/.ssh \
&& chmod 700 ~/.ssh \
&& ssh-keyscan github.com | tee ~/.ssh/known_hosts \
&& printf "Installed base utils\nInstalling docker\n" \
&& printf "\n\n\t🐋\t Installed base utils\nInstalling docker \t🐋\t\n\n" \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
&& apt-get -yq update \
&& apt-get -yq install --no-install-recommends docker-ce-cli \
&& printf "Installing Node.JS\n" \
&& printf "\n\n\t🐋\t Installed $(docker -v)\n \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Installing Node.JS \t🐋\t\n\n" \
&& curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
&& DISTRO="$(lsb_release -s -c)" \
&& echo "deb https://deb.nodesource.com/node_${NODE_VERSION}.x $DISTRO main" | tee /etc/apt/sources.list.d/nodesource.list \
&& echo "deb-src https://deb.nodesource.com/node_${NODE_VERSION}.x $DISTRO main" | tee -a /etc/apt/sources.list.d/nodesource.list \
&& apt-get -yq update \
&& apt-get -yq install --no-install-recommends nodejs="${NODE_VERSION}*" \
&& printf "Installed Node.JS $(node -v)\n" \
&& printf "\n\n\t🐋\t Installed Node.JS $(node -v) \t🐋\t\n\n" \
&& dpkg-query -f '${binary:Package}\n' -W \
&& printf "Cleaning image\n" \
&& printf "\n\n\t🐋\t Cleaning image \t🐋\t\n\n" \
&& apt-get clean \
&& rm -rf /var/cache/* /var/log/* /var/lib/apt/lists/* /tmp/* || echo 'Failed to delete directories' \
&& printf "Cleaned up image\n"
&& printf "\n\n\t🐋\t Cleaned up image \t🐋\t\n\n"
ARG BUILD_TAG_VERSION="master"
ARG BUILD_TAG_VERSION="dev"
ARG BUILD_TAG="act"
ARG BUILD_REF="master"
LABEL org.opencontainers.image.vendor="catthehacker"
LABEL org.opencontainers.image.authors="me@hackerc.at"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images.git"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/tree/${BUILD_REF}/linux/${IMAGE}/${BUILD_TAG}/"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
USER root
+21
View File
@@ -0,0 +1,21 @@
ARG IMAGE=ghcr.io/catthehacker/alpine
ARG TAG=act-latest
FROM ${IMAGE}:${TAG}
ARG TARGETARCH
ARG TARGETVARIANT
SHELL [ "/bin/bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c" ]
RUN set -Eeuxo pipefail \
&& printf "Installing Go(lang)\n" \
&& sudo apk add --no-cache go
ARG BUILD_TAG_VERSION="dev"
ARG BUILD_TAG="go"
ARG BUILD_REF="master"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
+32
View File
@@ -0,0 +1,32 @@
ARG IMAGE=ghcr.io/catthehacker/ubuntu
ARG TAG=act-latest
FROM ${IMAGE}:${TAG}
ARG TARGETARCH
ARG TARGETVARIANT
SHELL [ "/bin/bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c" ]
RUN set -Eeuxo pipefail \
&& printf "\n\n\t🐋\t Installing JS tools \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Installed NPM $(npm -v) \t🐋\t\n\n" \
&& npm install -g npm \
&& npm install -g pnpm \
&& npm install -g yarn \
&& printf "\n\n\t🐋\t Installed NPM $(npm -v) \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Installed PNPM $(pnpm -v) \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Installed YARN $(yarn -v) \t🐋\t\n\n" \
&& npm install -g grunt gulp n parcel-bundler typescript newman vercel webpack webpack-cli lerna \
&& npm install -g --unsafe-perm netlify-cli \
&& printf "\n\n\t🐋\t Cleaning image \t🐋\t\n\n" \
&& apt-get clean \
&& rm -rf /var/cache/* /var/log/* /var/lib/apt/lists/* /tmp/* || echo 'Failed to delete directories' \
&& printf "\n\n\t🐋\t Cleaned up image \t🐋\t\n\n"
ARG BUILD_TAG_VERSION="dev"
ARG BUILD_TAG="rust"
ARG BUILD_REF="master"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
+19
View File
@@ -0,0 +1,19 @@
ARG IMAGE=ghcr.io/catthehacker/alpine
ARG TAG=act-latest
FROM ${IMAGE}:${TAG}
ARG TARGETARCH
ARG TARGETVARIANT
SHELL [ "/bin/bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c" ]
RUN #TODO
ARG BUILD_TAG_VERSION="dev"
ARG BUILD_TAG="rust"
ARG BUILD_REF="master"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
+15 -17
View File
@@ -1,27 +1,27 @@
ARG BASEIMAGE=catthehacker/ubuntu
ARG IMAGE=ghcr.io/catthehacker/ubuntu
ARG TAG=act-latest
FROM ${BASEIMAGE}:${TAG}
FROM ${IMAGE}:${TAG}
ARG TARGETARCH
ARG TARGETVARIANT
# > ARGs before FROM are not accessible
ARG BASEIMAGE=catthehacker/ubuntu
ARG IMAGE=catthehacker/ubuntu
ARG TAG=act-latest
# > non-root user
ARG RUNNER=runner
SHELL [ "/bin/bash", "--login", "-o", "pipefail", "-c" ]
SHELL [ "/bin/bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c" ]
# > Create non-root user
RUN set -Eeuxo pipefail \
&& printf "Creating non-root user\n" \
&& printf "\n\n\t🐋\t Creating non-root user \t🐋\t\n\n" \
&& groupadd -g 1000 ${RUNNER} \
&& useradd -u 1000 -g ${RUNNER} -G sudo -m -s /bin/bash ${RUNNER} \
&& sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g' \
&& sed -i /etc/sudoers -re 's/^root.*/root ALL=(ALL:ALL) NOPASSWD: ALL/g' \
&& sed -i /etc/sudoers -re 's/^#includedir.*/## **Removed the include directive** ##"/g' \
&& echo "${RUNNER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
&& printf "Runner user: $(su - ${RUNNER} -c id)\n" \
&& printf "Created non-root user $(grep ${RUNNER} /etc/passwd)\n" \
&& printf "\n\n\t🐋\t Runner user: $(su - ${RUNNER} -c id) \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Created non-root user $(grep ${RUNNER} /etc/passwd) \t🐋\t\n\n" \
&& sed -i /etc/environment -e "s/USER=root/USER=${RUNNER}/g" \
&& echo "RUNNER_TEMP=/home/${RUNNER}/work/_temp" | tee -a /etc/environment \
&& mkdir -p "/home/${RUNNER}/work/_temp" \
@@ -30,18 +30,16 @@ RUN set -Eeuxo pipefail \
&& chmod 700 "/home/${RUNNER}/.ssh" \
&& ssh-keyscan github.com | tee "/home/${RUNNER}/.ssh/known_hosts" \
&& chmod 644 "/home/${RUNNER}/.ssh/known_hosts" \
&& chown -R ${RUNNER}:${RUNNER} "/home/${RUNNER}/.ssh"
&& chown -R ${RUNNER}:${RUNNER} "/home/${RUNNER}/.ssh" \
&& printf "\n\n\t🐋\t Finished building \t🐋\t\n\n"
ARG BUILD_TAG_VERSION="master"
ARG BUILD_TAG_VERSION="dev"
ARG BUILD_TAG="runner"
ARG BUILD_REF="master"
LABEL org.opencontainers.image.vendor="catthehacker"
LABEL org.opencontainers.image.authors="me@hackerc.at"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/linux/${BASEIMAGE}/${IMAGE_TYPE}"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images.git"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
USER ${RUNNER}
+20
View File
@@ -0,0 +1,20 @@
ARG IMAGE=ghcr.io/catthehacker/alpine
ARG TAG=act-latest
FROM ${IMAGE}:${TAG}
ARG TARGETARCH
ARG TARGETVARIANT
SHELL [ "/bin/bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c" ]
RUN set -euxo pipefail \
&& printf "Installing Rust\n" \
&& curl https://sh.rustup.rs -sSf | sh -s -- -y
ARG BUILD_TAG_VERSION="dev"
ARG BUILD_TAG="rust"
ARG BUILD_REF="master"
LABEL org.opencontainers.image.url="https://github.com/catthehacker/docker_images/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}