Skip to content

Commit

Permalink
AL: add argocd-plugin image
Browse files Browse the repository at this point in the history
  • Loading branch information
adalundhe committed Aug 21, 2024
1 parent a8a199b commit 37dd84b
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 2 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build_argocd_plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is a basic workflow to help you get started with Actions

name: Build ArgoCD Plugin Images

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
paths:
- .github/workflows/build_argocd_plugin.yml
- argocd/plugin/Dockerfile.argocd-plugin
- resources/argocd/plugin/*
pull_request:
branches: [ main ]
paths:
- .github/workflows/build_argocd_plugin.yml
- argocd/plugin/Dockerfile.argocd-plugin
- resources/argocd/plugin/*

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
IMAGE_OS: "bookworm"
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

build_argocd_plugin:
strategy:
matrix:
python_version: ["3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
file: argocd/plugin/Dockerfile.argocd-plugin
tags: corpheus91/argocd-plugin:python-${{matrix.python_version}}-${{env.IMAGE_OS}}
build-args: |
VERSION=${{matrix.python_version}}
61 changes: 61 additions & 0 deletions argocd/plugins/Dockerfile.argocd-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
ARG VERSION

FROM python:${VERSION}-alpine

ARG USER=default
ENV HOME=/home/$USER

RUN apk update && \
apk add aws-cli \
bzip2 \
coreutils \
curl \
gcc \
sudo \
gnupg \
linux-headers \
make \
musl-dev \
patch \
tzdata \
tar \
gpg \
git \
bash \
nano \
ca-certificates \
coreutils \
gnupg \
wget \
grep \
docker \
openrc

RUN rc-update add docker boot

RUN pip install uv

RUN if [ ! -s usr/bin/env ] && [ -s bin/env ]; then \
mkdir -p usr/bin; \
ln -s ../../bin/env usr/bin/; \
fi

RUN adduser -D $USER \
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER \
&& chown -R ${USER} ${HOME} \
&& chmod -R a+rwX,o-w ${HOME}

COPY resources/argocd/plugins/wait_forever.sh /usr/local/bin/wait_forever.sh
RUN chmod +x /usr/local/bin/wait_forever.sh

RUN mkdir /scripts
COPY resources/argocd/plugins/kubectl-helm-alpine.sh /scripts/kubectl-helm-alpine.sh
RUN bash /scripts/kubectl-helm-alpine.sh

ENV PATH="$HOME/.krew/bin:$PATH"

USER $USER
WORKDIR $HOME

CMD [ "/usr/local/bin/wait_forever.sh" ]
8 changes: 6 additions & 2 deletions node/Dockerfile.node
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ARG BASE

FROM node:${VERSION}-${BASE}-slim
ARG REGISTRY_URL="https://registry.npmjs.org"
ARG NPM_TOKEN
ARG USERNAME=vscode
ARG USER_UID=5000
ARG USER_GID=$USER_UID
Expand All @@ -19,9 +20,12 @@ RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | g
apt update && apt install -y gh unzip;

WORKDIR /app
RUN npm install -g --registry=${REGISTRY_URL} \

COPY resources/node/install_via_npm.sh /app/install_via_npm.sh
RUN bash /app/install_via_npm.sh ${REGISTRY_URL} ${NPM_TOKEN} \
pnpm \
turbo
turbo \
&& rm -rf /app/install_via_npm.sh

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" && \
unzip -qq -o awscliv2.zip && \
Expand Down
213 changes: 213 additions & 0 deletions resources/argocd/plugins/kubectl-helm-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/kubectl-helm.md
# Maintainer: The VS Code and Codespaces Teams
#
# Syntax: ./kubectl-helm-debian.sh [kubectl verison] [Helm version] [minikube version] [kubectl SHA256] [Helm SHA256] [minikube SHA256]

set -e

KUBECTL_VERSION="${1:-"latest"}"
HELM_VERSION="${2:-"latest"}"
KUBECTL_SHA256="${4:-"automatic"}"
HELM_SHA256="${5:-"automatic"}"
USERNAME=${7:-"default"}

HELM_GPG_KEYS_URI="https://raw.githubusercontent.com/helm/helm/main/KEYS"
GPG_KEY_SERVERS="keyserver hkp://keyserver.ubuntu.com:80
keyserver hkps://keys.openpgp.org
keyserver hkp://keyserver.pgp.com"

if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi

# Determine the appropriate non-root user
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
USERNAME=root
fi

USERHOME="/home/$USERNAME"
if [ "$USERNAME" = "root" ]; then
USERHOME="/root"
fi


# Get central common setting
get_common_setting() {
if [ "${common_settings_file_loaded}" != "true" ]; then
curl -sfL "https://aka.ms/vscode-dev-containers/script-library/settings.env" 2>/dev/null -o /tmp/vsdc-settings.env || echo "Could not download settings file. Skipping."
common_settings_file_loaded=true
fi
if [ -f "/tmp/vsdc-settings.env" ]; then
local multi_line=""
if [ "$2" = "true" ]; then multi_line="-z"; fi
local result="$(grep ${multi_line} -oP "$1=\"?\K[^\"]+" /tmp/vsdc-settings.env | tr -d '\0')"
if [ ! -z "${result}" ]; then declare -g $1="${result}"; fi
fi
echo "$1=${!1}"
}

# Figure out correct version of a three part version number is not passed
find_version_from_git_tags() {
local variable_name=$1
local requested_version=${!variable_name}
if [ "${requested_version}" = "none" ]; then return; fi
local repository=$2
local prefix=${3:-"tags/v"}
local separator=${4:-"."}
local last_part_optional=${5:-"false"}
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
local escaped_separator=${separator//./\\.}
local last_part
if [ "${last_part_optional}" = "true" ]; then
last_part="(${escaped_separator}[0-9]+)?"
else
last_part="${escaped_separator}[0-9]+"
fi
local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
else
set +e
declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
set -e
fi
fi
if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
exit 1
fi
echo "${variable_name}=${!variable_name}"
}

# Function to run apk if needed
apt_get_update_if_needed()
{
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
echo "Running apk update..."
apk update
else
echo "Skipping apk update."
fi
}

# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update_if_needed
apk add "$@"
fi
}

# Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive

# Install dependencies
check_packages curl ca-certificates coreutils gnupg
if ! type git > /dev/null 2>&1; then
apt_get_update_if_needed
apk add git
fi

architecture="$(uname -m)"
case $architecture in
x86_64) architecture="amd64";;
aarch64 | armv8*) architecture="arm64";;
aarch32 | armv7* | armvhf*) architecture="arm";;
i?86) architecture="386";;
*) echo "(!) Architecture $architecture unsupported"; exit 1 ;;
esac

# Install the kubectl, verify checksum
echo "Downloading kubectl..."
if [ "${KUBECTL_VERSION}" = "latest" ] || [ "${KUBECTL_VERSION}" = "lts" ] || [ "${KUBECTL_VERSION}" = "current" ] || [ "${KUBECTL_VERSION}" = "stable" ]; then
KUBECTL_VERSION="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
else
find_version_from_git_tags KUBECTL_VERSION https://github.com/kubernetes/kubernetes
fi
if [ "${KUBECTL_VERSION::1}" != 'v' ]; then
KUBECTL_VERSION="v${KUBECTL_VERSION}"
fi
curl -sSL -o /usr/local/bin/kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${architecture}/kubectl"
chmod 0755 /usr/local/bin/kubectl
if [ "$KUBECTL_SHA256" = "automatic" ]; then
KUBECTL_SHA256="$(curl -sSL "https://dl.k8s.io/${KUBECTL_VERSION}/bin/linux/${architecture}/kubectl.sha256")"
fi
([ "${KUBECTL_SHA256}" = "dev-mode" ] || (echo "${KUBECTL_SHA256} */usr/local/bin/kubectl" | sha256sum -c -))
if ! type kubectl > /dev/null 2>&1; then
echo '(!) kubectl installation failed!'
exit 1
fi

# Install Helm, verify signature and checksum
echo "Downloading Helm..."
find_version_from_git_tags HELM_VERSION "https://github.com/helm/helm"
if [ "${HELM_VERSION::1}" != 'v' ]; then
HELM_VERSION="v${HELM_VERSION}"
fi
mkdir -p /tmp/helm
helm_filename="helm-${HELM_VERSION}-linux-${architecture}.tar.gz"
tmp_helm_filename="/tmp/helm/${helm_filename}"
curl -sSL "https://get.helm.sh/${helm_filename}" -o "${tmp_helm_filename}"
curl -sSL "https://github.com/helm/helm/releases/download/${HELM_VERSION}/${helm_filename}.asc" -o "${tmp_helm_filename}.asc"
export GNUPGHOME="/tmp/helm/gnupg"
mkdir -p "${GNUPGHOME}"
chmod 700 ${GNUPGHOME}
get_common_setting HELM_GPG_KEYS_URI
get_common_setting GPG_KEY_SERVERS true
curl -sSL "${HELM_GPG_KEYS_URI}" -o /tmp/helm/KEYS
echo -e "disable-ipv6\n${GPG_KEY_SERVERS}" > ${GNUPGHOME}/dirmngr.conf
gpg -q --import "/tmp/helm/KEYS"
if ! gpg --verify "${tmp_helm_filename}.asc" > ${GNUPGHOME}/verify.log 2>&1; then
echo "Verification failed!"
cat /tmp/helm/gnupg/verify.log
exit 1
fi
if [ "${HELM_SHA256}" = "automatic" ]; then
curl -sSL "https://get.helm.sh/${helm_filename}.sha256" -o "${tmp_helm_filename}.sha256"
curl -sSL "https://github.com/helm/helm/releases/download/${HELM_VERSION}/${helm_filename}.sha256.asc" -o "${tmp_helm_filename}.sha256.asc"
if ! gpg --verify "${tmp_helm_filename}.sha256.asc" > /tmp/helm/gnupg/verify.log 2>&1; then
echo "Verification failed!"
cat /tmp/helm/gnupg/verify.log
exit 1
fi
HELM_SHA256="$(cat "${tmp_helm_filename}.sha256")"
fi
([ "${HELM_SHA256}" = "dev-mode" ] || (echo "${HELM_SHA256} *${tmp_helm_filename}" | sha256sum -c -))
tar xf "${tmp_helm_filename}" -C /tmp/helm
mv -f "/tmp/helm/linux-${architecture}/helm" /usr/local/bin/
chmod 0755 /usr/local/bin/helm
rm -rf /tmp/helm
if ! type helm > /dev/null 2>&1; then
echo '(!) Helm installation failed!'
exit 1
fi

set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew

echo -e "\nDone!"
3 changes: 3 additions & 0 deletions resources/argocd/plugins/wait_forever.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

sleep infinity
7 changes: 7 additions & 0 deletions resources/node/.envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
WORKDIR_PATH=${WORKDIR_PATH:-"$HOME"}
NPM_REGISTRY_URL=${NPM_REGISTRY_URL:-}
NPM_AUTH_TOKEN=${NPM_AUTH_TOKEN:-}

if [[ "$NPM_REGISTRY_URL" != "" && "$NPM_AUTH_TOKEN" != "" ]]; then
npm config set registry=$NPM_REGISTRY_URL
npm config set $NPM_AUTH_TOKEN
fi

if [[ -e "$WORKDIR_PATH/package.json" ]]; then
pnpm install
Expand Down
15 changes: 15 additions & 0 deletions resources/node/install_via_npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

REGISTRY=${1:-}
TOKEN=${2:-}

npm config set registry=$REGISTRY

if [[ "$TOKEN" != "" ]]; then
npm config set $TOKEN
fi

npm install -g $@

npm config set registry=https://registry.npmjs.org/
npm config set //registry.npmjs.org/:_authToken=""

0 comments on commit 37dd84b

Please sign in to comment.