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
+68
View File
@@ -0,0 +1,68 @@
ARG IMAGE=alpine
ARG TAG=3.13
FROM ${IMAGE}:${TAG}
# > automatic buildx ARGs
ARG TARGETARCH
ARG TARGETVARIANT
# > ARGs before FROM are not accessible
ARG IMAGE=alpine
ARG TAG=3.13
ARG IMAGEOS=alpine
SHELL [ "/bin/ash", "-l", "-o", "pipefail", "-c" ]
# > setup environment required for GitHub Actions, install dependencies/packages
RUN set -euxo pipefail \
&& printf "\n\n\t🐋\t Build started \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Adding environment variables \t🐋\t\n\n" \
&& echo "USER=$(whoami)" | tee -a /etc/environment \
&& echo "RUNNER_USER=$(whoami)" | tee -a /etc/environment \
&& echo "IMAGE_OS=${IMAGE}" | tee -a /etc/environment \
&& echo "ImageOS=${IMAGE}" | tee -a /etc/environment \
#&& echo "LSB_RELEASE=${DISTRIB_RELEASE}" | tee -a /etc/environment \
&& AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache \
&& echo "AGENT_TOOLSDIRECTORY=${AGENT_TOOLSDIRECTORY}" | tee -a /etc/environment \
&& echo "RUN_TOOL_CACHE=${AGENT_TOOLSDIRECTORY}" | tee -a /etc/environment \
&& echo "DEPLOYMENT_BASEPATH=/opt/runner" | tee -a /etc/environment \
&& echo ". /etc/environment" | tee -a /etc/profile \
&& printf "\n\n\t🐋\t Creating tool cache directory and '/github' \t🐋\t\n\n" \
&& mkdir -p ${AGENT_TOOLSDIRECTORY} \
&& chown 1000:1000 ${AGENT_TOOLSDIRECTORY} \
&& chmod 0777 ${AGENT_TOOLSDIRECTORY} \
&& mkdir -p /github \
&& chown 1000:1000 /github \
&& chmod 0777 /github \
&& printf "\n\n\t🐋\t Installing packages \t🐋\t\n\n" \
&& apk --no-cache add bash openssh-client gawk jq curl git wget sudo gnupg ca-certificates yaml zstd zip unzip xz icu build-base python3 nodejs docker-cli \
&& ln -s $(which python3) /usr/local/bin/python \
&& printf "\n\n\t🐋\t Docker: $(docker -v) \t🐋\t\n\n" \
&& printf "\n\n\t🐋\t Node: $(node -v) \t🐋\t\n\n" \
&& apk list -I | sort \
&& 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 "\n\n\t🐋\t Installed base utils \t🐋\t\n\n" \
&& 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' \
&& printf "\n\n\t🐋\t Cleaning image \t🐋\t\n\n" \
&& apk clean cache \
&& rm -rf /var/cache/* /var/log/* /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="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/tree/${BUILD_REF}/linux/${IMAGEOS}/${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}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
USER root
-65
View File
@@ -1,65 +0,0 @@
ARG BASEIMAGE=node
ARG TAG=lts-alpine3.13
FROM ${BASEIMAGE}:${TAG}
ARG TARGETARCH
ARG TARGETVARIANT
# > ARGs before FROM are not accessible
ARG BASEIMAGE=alpine
ARG TAG=3.13
ARG AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
ARG IMAGE_TYPE=act
ENV ImageOS=alpine
SHELL [ "/bin/ash", "-o", "pipefail", "-l", "-c" ]
# > setup environment required for GitHub Actions, install dependencies/packages
RUN set -euxo pipefail \
&& printf "Build started\nAdding environment variables\n\n" \
&& echo "USER=$(whoami)" | tee -a /etc/environment \
&& echo "RUNNER_USER=$(whoami)" | tee -a /etc/environment \
&& echo "IMAGE_OS=${ImageOS}" | tee -a /etc/environment \
&& echo "ImageOS=${ImageOS}" | tee -a /etc/environment \
#&& echo "LSB_RELEASE=${DISTRIB_RELEASE}" | tee -a /etc/environment \
&& echo "AGENT_TOOLSDIRECTORY=${AGENT_TOOLSDIRECTORY}" | tee -a /etc/environment \
&& echo "RUN_TOOL_CACHE=${AGENT_TOOLSDIRECTORY}" | tee -a /etc/environment \
&& echo "DEPLOYMENT_BASEPATH=/opt/runner" | tee -a /etc/environment \
&& echo ". /etc/environment" | tee -a /etc/profile \
&& printf "Creating tool cache directory and '/github'\n\n" \
&& mkdir -p ${AGENT_TOOLSDIRECTORY} \
&& chown 1000:1000 ${AGENT_TOOLSDIRECTORY} \
&& chmod 0777 ${AGENT_TOOLSDIRECTORY} \
&& mkdir -p /github \
&& chown 1000:1000 /github \
&& chmod 0777 /github \
&& printf "Installing packages\n\n" \
&& apk --no-cache add openssh-client gawk jq curl git wget sudo gnupg ca-certificates yaml zstd zip unzip xz icu build-base python3 \
&& printf "Creating ~/.ssh and adding 'github.com'\n\n" \
&& mkdir -p ~/.ssh \
&& chmod 700 ~/.ssh \
&& ssh-keyscan github.com | tee ~/.ssh/known_hosts \
&& printf "Installed base utils\nInstalling docker\n" \
&& apk --no-cache add docker-cli \
&& printf "Cleaning image\n" \
&& apk clean cache \
&& rm -rf /var/cache/* /var/log/* /tmp/* || echo 'Failed to delete directories' \
&& printf "Cleaned up image\n"
ARG BUILD_TAG_VERSION="master"
ARG BUILD_TAG=${IMAGE_TYPE}
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/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images.git"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
SHELL [ "/bin/ash", "-l", "-c" ]
# > Force bash with environment
ENTRYPOINT [ "/bin/ash", "-l", "-c" ]
-21
View File
@@ -1,21 +0,0 @@
ARG BASEIMAGE=catthehacker/alpine
ARG TAG=act
FROM ${BASEIMAGE}:${TAG}
SHELL [ "/bin/ash", "-o", "pipefail", "-l", "-c" ]
RUN set -Eeuxo pipefail \
&& printf "Installing Go(lang)\n" \
&& sudo apk add --no-cache go
ARG BUILD_TAG_VERSION="master"
ARG BUILD_TAG="go"
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/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images.git"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
-39
View File
@@ -1,39 +0,0 @@
ARG BASEIMAGE=catthehacker/alpine
ARG TAG=act
FROM ${BASEIMAGE}:${TAG}
SHELL [ "/bin/ash", "-o", "pipefail", "-l", "-c" ]
ARG RUNNER=runner
# > Create non-root user
RUN set -euxo pipefail \
&& printf "Creating non-root user\n" \
&& addgroup -S ${RUNNER} -g 1000 && adduser -S ${RUNNER} -u 1000 -G ${RUNNER} -s /usr/bin/fish \
&& 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" \
&& 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" \
&& chown -R ${RUNNER}:${RUNNER} "/home/${RUNNER}/work" \
&& mkdir -p "/home/${RUNNER}/.ssh" \
&& 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"
ARG BUILD_TAG_VERSION="master"
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/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images.git"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}
-21
View File
@@ -1,21 +0,0 @@
ARG BASEIMAGE=catthehacker/alpine
ARG TAG=act
FROM ${BASEIMAGE}:${TAG}
SHELL [ "/bin/ash", "-o", "pipefail", "-l", "-c" ]
RUN set -Eeuxo pipefail \
&& printf "Installing Rust\n" \
&& curl https://sh.rustup.rs -sSf | sh -s -- -y
ARG BUILD_TAG_VERSION="master"
ARG BUILD_TAG="rust"
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/tree/${BUILD_REF}/linux/${ImageOS}/${BUILD_TAG}/"
LABEL org.opencontainers.image.source="https://github.com/catthehacker/docker_images.git"
LABEL org.opencontainers.image.version=${BUILD_TAG_VERSION}
LABEL org.opencontainers.image.title=${BUILD_TAG}-${TARGETARCH}-${TARGETVARIANT}
LABEL org.opencontainers.image.revision=${BUILD_REF}