Skip to content

Commit

Permalink
feat: add docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
imranismail committed Nov 10, 2023
1 parent a5c8aad commit 92efbbf
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM public.ecr.aws/ubuntu/ubuntu:23.04_stable

SHELL ["/usr/bin/env", "-S", "bash", "-cl"]

RUN apt-get update -q && apt-get install -y git curl python3 python3-pip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN adduser --uid 999 --shell /bin/bash --home /home/argocd --disabled-password argocd
ENV PATH="${PATH}:/asdf/.asdf/shims:/asdf/.asdf/bin"

USER argocd
WORKDIR /home/argocd

RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile

RUN asdf plugin add kustomize && \
asdf plugin add helm && \
asdf plugin add krm-function https://github.com/imranismail/asdf-krm-function.git && \
asdf install kustomize latest && \
asdf global kustomize latest && \
asdf install helm latest && \
asdf global helm latest

COPY plugin /usr/local/bin/
COPY plugin.yaml ./cmp-server/config/
6 changes: 6 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: build
build:
@docker build -t ghcr.io/imranismail/asdf-krm-function --platform linux/amd64 .
.PHONY: push
push:
@docker push ghcr.io/imranismail/asdf-krm-function
77 changes: 77 additions & 0 deletions docker/plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env -S bash -l

set -euo pipefail

init_asdf() {
# if no .tool-versions found return function early
if [[ ! -f ".tool-versions" ]]; then
return
fi

echo "Initializing asdf..."

# try to install additional tools
error=$(asdf install)
errorcode=$?

# if there are missing plugins, install them and try again
if [[ $errorcode -ne 0 ]]; then
case $error in
*"plugin is not installed"*)
missing_plugins=$(echo "$error" | awk '{ print $1 }')

for plugin in $missing_plugins; do
asdf plugin add "$plugin"
done

asdf install
;;
*)
echo "Error installing dependencies: $error"
exit 1
;;
esac
fi

echo "asdf initialization complete"
}

init_python() {
if [[ ! -f "requirements.txt" ]]; then
return
fi

echo "Initializing python..."
pip install -r requirements.txt
echo "Python initialization complete"
}

init() {
init_asdf
init_python
}

generate() {
kustomize build --enable-alpha-plugins --enable-exec --load-restrictor LoadRestrictionsNone
}

main() {
case "$1" in
"init")
init
;;
"generate")
generate
;;
*)
echo "Unknown command: $1"
echo "Usage: $0 <init|generate>"
echo ""
echo "init: install dependencies"
echo "generate: generate kustomize output"
exit 1
;;
esac
}

main "$@"
12 changes: 12 additions & 0 deletions docker/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: argoproj.io/v1alpha1
kind: ConfigManagementPlugin
metadata:
name: asdf-kustomize
spec:
init:
command: [plugin]
args: [init]
generate:
command: [plugin]
args: [generate]
preserveFileMode: true
77 changes: 77 additions & 0 deletions plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env -S bash -l

set -euo pipefail

init_asdf() {
# if no .tool-versions found return function early
if [[ ! -f ".tool-versions" ]]; then
return
fi

echo "Initializing asdf..."

# try to install additional tools
error=$(asdf install)
errorcode=$?

# if there are missing plugins, install them and try again
if [[ $errorcode -ne 0 ]]; then
case $error in
*"plugin is not installed"*)
missing_plugins=$(echo "$error" | awk '{ print $1 }')

for plugin in $missing_plugins; do
asdf plugin add "$plugin"
done

asdf install
;;
*)
echo "Error installing dependencies: $error"
exit 1
;;
esac
fi

echo "asdf initialization complete"
}

init_python() {
if [[ ! -f "requirements.txt" ]]; then
return
fi

echo "Initializing python..."
pip install -r requirements.txt
echo "Python initialization complete"
}

init() {
init_asdf
init_python
}

generate() {
kustomize build --enable-alpha-plugins --enable-exec --load-restrictor LoadRestrictionsNone
}

main() {
case "$1" in
"init")
init
;;
"generate")
generate
;;
*)
echo "Unknown command: $1"
echo "Usage: $0 <init|generate>"
echo ""
echo "init: install dependencies"
echo "generate: generate kustomize output"
exit 1
;;
esac
}

main "$@"

0 comments on commit 92efbbf

Please sign in to comment.