Skip to content

Commit

Permalink
add mutliple images update
Browse files Browse the repository at this point in the history
  • Loading branch information
ming.hsu committed Jun 7, 2021
1 parent 7703437 commit 8359c10
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +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
COPY entrypoint.sh /bin/
RUN chmod +x /bin/entrypoint.sh

ENV SSH_KEY=
ENV IMAGE_REPO=
ENV IMAGES=
ENV IMAGE_TAG=
ENV MANIFEST_HOST=
ENV MANIFEST_USER=
ENV MANIFEST_REPO=
ENV SVC_PATH=
ENV MANIFEST_BRANCH=
ENV KUSTOMIZATION=

ENTRYPOINT ["/app/entrypoint.sh"]
ENTRYPOINT ["/bin/entrypoint.sh"]
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ A Drone CI plugin for updating an image tag 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
- `IMAGE_REPO`: Image repository
- `MANIFEST_HOST`: Manifest git server host
- `MANIFEST_USER`: Manifest git user
- `MANIFEST_REPO`: Manifest git repository
- `MANIFEST_BRANCH`: Manifest repository branch
- `IMAGES`: Updated images (comma-separated list)
- `IMAGE_TAG`: Image tag generated in current build
- `SVC_PATH`: Service kustomization path relative to the project root
- `KUSTOMIZATION`: Kustomization path relative to the project root

Example usage in a Drone pipeline:
```yaml
...
- name: push-registry
- name: publish-mysvc1
image: plugins/docker
settings:
context: .
Expand All @@ -23,27 +24,45 @@ Example usage in a Drone pipeline:
password:
from_secret: docker_password
registry: harbor.mycompany.com
repo: harbor.mycompany.com/myuser/mysvc
repo: harbor.mycompany.com/myuser/mysvc1
tags:
- ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}
- latest
when:
event: push
- name: publish-mysvc2
image: plugins/docker
settings:
context: .
dockerfile: ./Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
registry: harbor.mycompany.com
repo: harbor.mycompany.com/myuser/mysvc2
tags:
- ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}
- latest
when:
event: push
- name: update-kustomization
pull: if-not-exists
image: minghsu0107/update-kustomization:v1.0.2
image: minghsu0107/update-kustomization:v1.0.3
environment:
SSH_KEY:
from_secret: ssh_key
MANIFEST_HOST: git.mycompany.com
MANIFEST_USER: myuser
MANIFEST_REPO: mysvc
IMAGE_REPO: harbor.mycompany.com/myuser/mysvc
MANIFEST_BRANCH: ${DRONE_COMMIT_BRANCH}
IMAGES: harbor.mycompany.com/myuser/mysvc1,harbor.mycompany.com/myuser/mysvc2
IMAGE_TAG: ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}
SVC_PATH: staging/mysvc
KUSTOMIZATION: staging/mysvc
when:
event: push
depends_on:
- push-registry
- publish-mysvc1
- publish-mysvc2
```
In the above example, the image tag is in the form of `${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}`, where `DRONE_COMMIT_BRANCH` and `DRONE_COMMIT_SHA` are environment variables provided by Drone at run time.
12 changes: 10 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
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 $IMAGE_REPO:$IMAGE_TAG
git add . && git commit -m "🚀 update to ${IMAGE_TAG}"

git checkout $MANIFEST_BRANCH
cd $MANIFEST_REPO/$KUSTOMIZATION

for IMAGE in $(echo $IMAGES | sed "s/,/ /g")
do
kustomize edit set image $IMAGE:$IMAGE_TAG
done

git add . && git commit --allow-empty -m "🚀 update to ${IMAGE_TAG}"
git push ssh://git@$MANIFEST_HOST/$MANIFEST_USER/$MANIFEST_REPO.git

0 comments on commit 8359c10

Please sign in to comment.