Skip to content

Commit ca95214

Browse files
authored
Merge pull request #29 from dtaniwaki/argo-example
Add argo example
2 parents de03781 + 6bfa089 commit ca95214

File tree

5 files changed

+145
-1
lines changed

5 files changed

+145
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
####################################################################################################
44
FROM golang:1.11.4 as git-ghost-dev
55

6+
67
RUN apt-get update -q && apt-get install -yq --no-install-recommends \
78
git \
89
make \

examples/argo/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM ubuntu:16.04
2+
3+
RUN apt-get update -q && apt-get install -yq --no-install-recommends git && \
4+
apt-get clean && \
5+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
6+
7+
COPY . /code/
8+
WORKDIR /code

examples/argo/run.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
DIR=$(dirname "$0")
7+
8+
[[ -z "$GIT_GHOST_REPO" ]] && (echo "GIT_GHOST_REPO must be specified."; exit 1)
9+
[[ -z "$GIT_GHOST_REGISTRY" ]] && (echo "GIT_GHOST_REGISTRY must be specified."; exit 1)
10+
11+
kubectl get secret git-ghost-git-cred > /dev/null || (cat << EOS
12+
git-ghost-git-cred secret is needed.
13+
You can create it by:
14+
15+
$ kubectl create secret generic git-ghost-git-cred --from-file=sshkey=\$HOME/.ssh/id_rsa
16+
17+
EOS
18+
exit 1)
19+
20+
kubectl get secret git-ghost-docker-cred > /dev/null || (cat << EOS
21+
git-ghost-docker-cred secret is needed.
22+
You can create it by:
23+
24+
$ kubectl create secret docker-registry git-ghost-docker-cred --docker-username=YOUR_NAME --docker-password=YOUR_PASSWORD
25+
26+
EOS
27+
exit 1)
28+
29+
IMAGE_PREFIX=
30+
if [[ -z "$IMAGE_PREFIX" ]]; then
31+
IMAGE_PREFIX=dtaniwaki/
32+
fi
33+
34+
IMAGE_TAG=
35+
if [[ -z "$IMAGE_TAG" ]]; then
36+
IMAGE_TAG="v0.1.1"
37+
fi
38+
39+
GIT_REPO=`git remote get-url origin`
40+
git diff --exit-code HEAD > /dev/null && (echo "Make some local modification to try the example."; exit 1)
41+
HASHES=`git ghost push origin/master`
42+
GIT_COMMIT_HASH=`echo $HASHES | cut -f 1 -d " "`
43+
DIFF_HASH=`echo $HASHES | cut -f 2 -d " "`
44+
45+
argo submit --watch -p image-prefix=$IMAGE_PREFIX -p image-tag=$IMAGE_TAG -p git-repo=$GIT_REPO -p git-ghost-repo=$GIT_GHOST_REPO -p git-ghost-registry=$GIT_GHOST_REGISTRY -p git-commit-hash=$GIT_COMMIT_HASH -p diff-hash=$DIFF_HASH $DIR/workflow.yaml --loglevel debug

examples/argo/workflow.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
kind: Workflow
2+
apiVersion: v1
3+
metadata:
4+
generateName: git-ghost-argo-example-
5+
labels:
6+
app: git-ghost-argo-example
7+
spec:
8+
arguments:
9+
parameters:
10+
- name: image-prefix
11+
globalName: image-prefix
12+
- name: image-tag
13+
globalName: image-tag
14+
- name: git-repo
15+
globalName: git-repo
16+
- name: git-ghost-repo
17+
globalName: git-ghost-repo
18+
- name: git-ghost-registry
19+
globalName: git-ghost-registry
20+
- name: git-commit-hash
21+
globalName: git-commit-hash
22+
- name: diff-hash
23+
globalName: diff-hash
24+
entrypoint: steps
25+
templates:
26+
- name: steps
27+
steps:
28+
- - name: build-image
29+
template: build-image
30+
- - name: job
31+
template: job
32+
- name: build-image
33+
initContainers:
34+
- name: init
35+
image: "{{workflow.parameters.image-prefix}}git-ghost-cli:{{workflow.parameters.image-tag}}"
36+
imagePullPolicy: IfNotPresent
37+
command: ["bash"]
38+
args:
39+
- "-c"
40+
- "git clone {{workflow.parameters.git-repo}} . && git checkout {{workflow.parameters.git-commit-hash}} && git ghost pull -v {{workflow.parameters.git-commit-hash}} {{workflow.parameters.diff-hash}}"
41+
workingDir: /workspace
42+
env:
43+
- name: GIT_SSH_COMMAND
44+
value: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /etc/git-secret/sshkey"
45+
- name: GIT_GHOST_REPO
46+
value: "{{workflow.parameters.git-ghost-repo}}"
47+
mirrorVolumeMounts: true
48+
container:
49+
name: kaniko
50+
image: gcr.io/kaniko-project/executor:v0.9.0
51+
imagePullPolicy: IfNotPresent
52+
args:
53+
- --context=/workspace
54+
- --dockerfile=/workspace/examples/argo/Dockerfile
55+
- --destination={{workflow.parameters.git-ghost-registry}}:{{workflow.parameters.git-commit-hash}}-{{workflow.parameters.diff-hash}}
56+
volumeMounts:
57+
- name: code
58+
mountPath: /workspace
59+
- name: git-secret
60+
mountPath: /etc/git-secret
61+
- name: docker-cred
62+
mountPath: /root
63+
volumes:
64+
- name: code
65+
emptyDir:
66+
- name: git-secret
67+
secret:
68+
secretName: git-ghost-git-cred
69+
defaultMode: 256
70+
- name: docker-cred
71+
projected:
72+
sources:
73+
- secret:
74+
name: git-ghost-docker-cred
75+
items:
76+
- key: .dockerconfigjson
77+
path: .docker/config.json
78+
- name: job
79+
metadata:
80+
labels:
81+
git-commit-hash: "{{workflow.parameters.git-commit-hash}}"
82+
diff-hash: "{{workflow.parameters.diff-hash}}"
83+
container:
84+
image: "{{workflow.parameters.git-ghost-registry}}:{{workflow.parameters.git-commit-hash}}-{{workflow.parameters.diff-hash}}"
85+
command: ["git"]
86+
args:
87+
- diff
88+
- HEAD
89+
imagePullSecrets:
90+
- name: git-ghost-docker-cred

examples/k8s/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exit 1)
3232

3333
IMAGE_PREFIX=
3434
if [[ -z "$IMAGE_PREFIX" ]]; then
35-
IMAGE_PREFIX=dtaniwaki
35+
IMAGE_PREFIX=dtaniwaki/
3636
fi
3737

3838
IMAGE_TAG=

0 commit comments

Comments
 (0)