From 8efc66c5d88a728253a36747fbc495758a765dec Mon Sep 17 00:00:00 2001 From: "ming.hsu" Date: Thu, 3 Jun 2021 18:25:58 +0800 Subject: [PATCH] first commit --- Dockerfile | 15 +++++++++++++++ README.md | 29 +++++++++++++++++++++++++++++ entrypoint.sh | 7 +++++++ 3 files changed, 51 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0e6e539 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM line/kubectl-kustomize:1.20.2-3.9.1 + +RUN mkdir -p /app +WORKDIR /app +COPY entrypoint.sh . +RUN chmod +x entrypoint.sh + +ENV SSH_KEY= +ENV CONTAINER_REPO= +ENV MANIFEST_HOST= +ENV MANIFEST_USER= +ENV MANIFEST_REPO= +ENV SVC_PATH= + +ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..50fabc2 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Update Kustomization +A Drone CI plugin for updating an image tag in using kustomize. + +Environment variables: +- `SSH_KEY`: Base64-encoded private key of your manifest repo +- `MANIFEST_HOST`: Git server host +- `MANIFEST_USER`: Git user +- `MANIFEST_REPO`: Git repository +- `CONTAINER_REPO`: Container repository +- `SVC_PATH`: Relative path to the target service manifest + +Example usage in a Drone pipeline: +```yaml +... +- name: update-kustomization + pull: if-not-exists + image: minghsu0107/update-kustomization:v1.0.0 + environment: + SSH_KEY: + from_secret: ssh_key + MANIFEST_HOST: git.mycompany.com + MANIFEST_USER: myuser + MANIFEST_REPO: mysvc + CONTAINER_REPO: harbor.mycompany.com/myuser/mysvc + SVC_PATH: staging/mysvc + when: + event: push +``` +Where `staging/mysvc` is the kustomization folder path relative to the project root. \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..954a52c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh +apk update && apk add --no-cache git && apk add --no-cache openssh +mkdir -p ~/.ssh && echo $SSH_KEY | base64 -d > ~/.ssh/id_rsa && chmod 700 ~/.ssh/id_rsa && ssh-keyscan $MANIFEST_HOST >> ~/.ssh/known_hosts +rm -rf $MANIFEST_REPO && git clone ssh://git@$MANIFEST_HOST/$MANIFEST_USER/$MANIFEST_REPO.git +cd $MANIFEST_REPO/$SVC_PATH && kustomize edit set image $CONTAINER_REPO:${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7} +git add . && git commit -m "🚀 update to ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}" +git push ssh://git@$MANIFEST_HOST/$MANIFEST_USER/$MANIFEST_REPO.git \ No newline at end of file