-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ming.hsu
committed
Jun 3, 2021
0 parents
commit 8efc66c
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |