Skip to content

Commit 8359c10

Browse files
author
ming.hsu
committed
add mutliple images update
1 parent 7703437 commit 8359c10

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
FROM line/kubectl-kustomize:1.20.2-3.9.1
22

3-
RUN mkdir -p /app
4-
WORKDIR /app
5-
COPY entrypoint.sh .
6-
RUN chmod +x entrypoint.sh
3+
COPY entrypoint.sh /bin/
4+
RUN chmod +x /bin/entrypoint.sh
75

86
ENV SSH_KEY=
9-
ENV IMAGE_REPO=
7+
ENV IMAGES=
108
ENV IMAGE_TAG=
119
ENV MANIFEST_HOST=
1210
ENV MANIFEST_USER=
1311
ENV MANIFEST_REPO=
14-
ENV SVC_PATH=
12+
ENV MANIFEST_BRANCH=
13+
ENV KUSTOMIZATION=
1514

16-
ENTRYPOINT ["/app/entrypoint.sh"]
15+
ENTRYPOINT ["/bin/entrypoint.sh"]

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ A Drone CI plugin for updating an image tag using kustomize.
33

44
Environment variables:
55
- `SSH_KEY`: Base64-encoded private key of your manifest repo
6-
- `MANIFEST_HOST`: Git server host
7-
- `MANIFEST_USER`: Git user
8-
- `MANIFEST_REPO`: Git repository
9-
- `IMAGE_REPO`: Image repository
6+
- `MANIFEST_HOST`: Manifest git server host
7+
- `MANIFEST_USER`: Manifest git user
8+
- `MANIFEST_REPO`: Manifest git repository
9+
- `MANIFEST_BRANCH`: Manifest repository branch
10+
- `IMAGES`: Updated images (comma-separated list)
1011
- `IMAGE_TAG`: Image tag generated in current build
11-
- `SVC_PATH`: Service kustomization path relative to the project root
12+
- `KUSTOMIZATION`: Kustomization path relative to the project root
1213

1314
Example usage in a Drone pipeline:
1415
```yaml
1516
...
16-
- name: push-registry
17+
- name: publish-mysvc1
1718
image: plugins/docker
1819
settings:
1920
context: .
@@ -23,27 +24,45 @@ Example usage in a Drone pipeline:
2324
password:
2425
from_secret: docker_password
2526
registry: harbor.mycompany.com
26-
repo: harbor.mycompany.com/myuser/mysvc
27+
repo: harbor.mycompany.com/myuser/mysvc1
28+
tags:
29+
- ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}
30+
- latest
31+
when:
32+
event: push
33+
- name: publish-mysvc2
34+
image: plugins/docker
35+
settings:
36+
context: .
37+
dockerfile: ./Dockerfile
38+
username:
39+
from_secret: docker_username
40+
password:
41+
from_secret: docker_password
42+
registry: harbor.mycompany.com
43+
repo: harbor.mycompany.com/myuser/mysvc2
2744
tags:
2845
- ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}
2946
- latest
3047
when:
3148
event: push
3249
- name: update-kustomization
3350
pull: if-not-exists
34-
image: minghsu0107/update-kustomization:v1.0.2
51+
image: minghsu0107/update-kustomization:v1.0.3
3552
environment:
3653
SSH_KEY:
3754
from_secret: ssh_key
3855
MANIFEST_HOST: git.mycompany.com
3956
MANIFEST_USER: myuser
4057
MANIFEST_REPO: mysvc
41-
IMAGE_REPO: harbor.mycompany.com/myuser/mysvc
58+
MANIFEST_BRANCH: ${DRONE_COMMIT_BRANCH}
59+
IMAGES: harbor.mycompany.com/myuser/mysvc1,harbor.mycompany.com/myuser/mysvc2
4260
IMAGE_TAG: ${DRONE_COMMIT_BRANCH}-${DRONE_COMMIT_SHA:0:7}
43-
SVC_PATH: staging/mysvc
61+
KUSTOMIZATION: staging/mysvc
4462
when:
4563
event: push
4664
depends_on:
47-
- push-registry
65+
- publish-mysvc1
66+
- publish-mysvc2
4867
```
4968
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.

entrypoint.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
apk update && apk add --no-cache git && apk add --no-cache openssh
33
mkdir -p ~/.ssh && echo $SSH_KEY | base64 -d > ~/.ssh/id_rsa && chmod 700 ~/.ssh/id_rsa && ssh-keyscan $MANIFEST_HOST >> ~/.ssh/known_hosts
44
rm -rf $MANIFEST_REPO && git clone ssh://git@$MANIFEST_HOST/$MANIFEST_USER/$MANIFEST_REPO.git
5-
cd $MANIFEST_REPO/$SVC_PATH && kustomize edit set image $IMAGE_REPO:$IMAGE_TAG
6-
git add . && git commit -m "🚀 update to ${IMAGE_TAG}"
5+
6+
git checkout $MANIFEST_BRANCH
7+
cd $MANIFEST_REPO/$KUSTOMIZATION
8+
9+
for IMAGE in $(echo $IMAGES | sed "s/,/ /g")
10+
do
11+
kustomize edit set image $IMAGE:$IMAGE_TAG
12+
done
13+
14+
git add . && git commit --allow-empty -m "🚀 update to ${IMAGE_TAG}"
715
git push ssh://git@$MANIFEST_HOST/$MANIFEST_USER/$MANIFEST_REPO.git

0 commit comments

Comments
 (0)