Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ming.hsu committed Jun 3, 2021
0 parents commit 8efc66c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8efc66c

Please sign in to comment.