|
1 | 1 | +++ |
2 | 2 | title = "GitOps Pipelines Example" |
3 | 3 | date = 2026-05-29 |
4 | | -updated= 2026-05-29 |
| 4 | +updated= 2026-06-03 |
5 | 5 | +++ |
6 | 6 |
|
| 7 | +## Pipeline Config {#pipeline-config} |
| 8 | + |
7 | 9 | This is an example in GitLab, though I think it can be trivially ported elsewhere (me thinks) |
8 | 10 |
|
9 | 11 | ```yaml |
@@ -33,4 +35,66 @@ container: |
33 | 35 | - buildah build -t "$CI_REGISTRY_IMAGE/container:${CI_COMMIT_SHA}" ./container |
34 | 36 | - buildah push "$CI_REGISTRY_IMAGE/container:${CI_COMMIT_SHA}" |
35 | 37 |
|
| 38 | +make_commit: |
| 39 | + image: alpine/git # Might be better to just an alpine container and add git manually |
| 40 | + stage: deploy |
| 41 | + script: |
| 42 | + - git config --global user.name "Evil Bot" |
| 43 | + - git config --global user.email "EvilBot@evilplace.com" |
| 44 | + - git clone "https://your.repo.com" |
| 45 | + # Edit your manifests using whatever: yq, sed, awk |
| 46 | + # This one changes the image version, but you can do whatever your hear desires |
| 47 | + - yq -i '.images[].newTag = strenv(CI_COMMIT_SHA)' kustomization.yml |
| 48 | + |
| 49 | + # Commit and push! |
| 50 | + - git add kustomization.yaml |
| 51 | + - git commit -m "Deploy ${CI_COMMIT_SHA} to dev!!!" |
| 52 | + - git push origin main |
| 53 | +``` |
| 54 | +
|
| 55 | +As an aside, when using `sed`, things get a bit trickly in regards to quoting, since you need quotes to expand the ENV variables, so you quote the whole thing and then use backslashes to escape the double quotes you want. |
| 56 | + |
| 57 | + |
| 58 | +## Kustomization.yaml {#kustomization-dot-yaml} |
| 59 | + |
| 60 | +Generally you would have Kustomization.yaml file in `base/` and then one in each of your overlays, for example |
| 61 | + |
| 62 | +```sh |
| 63 | +/base/Kustomization.yaml |
| 64 | +/overlays/dev/Kustomization.yaml |
| 65 | +/overlays/prod/Kustomization.yaml |
36 | 66 | ``` |
| 67 | + |
| 68 | +And in the file for `dev`, you might have something like this |
| 69 | + |
| 70 | +```yaml |
| 71 | +namePrefix: dev- |
| 72 | +resources: |
| 73 | +- ../../base |
| 74 | +- extra.yaml |
| 75 | +- dev-specific-stuff.yaml |
| 76 | +
|
| 77 | +# Modify yaml files in base using patches, which are just JSON patch documents. You can pass in a file or just inline it |
| 78 | +patches: |
| 79 | +- target: |
| 80 | + version: v1 |
| 81 | + group: route.openshift.io |
| 82 | + kind: Route |
| 83 | + name: shrunk |
| 84 | + patch: |- |
| 85 | + - op: replace |
| 86 | + path: /spec/host |
| 87 | + value: bleh.com |
| 88 | +
|
| 89 | +# k8 has builtin configuration for images without using patches |
| 90 | +# Whenever you use frontend for an image, like the following |
| 91 | +# image: frontend |
| 92 | +# k8 will replace frontend with the give name and tag |
| 93 | +images: |
| 94 | +- name: frontend |
| 95 | + newName: your.registry.com |
| 96 | + newTag: "latest" |
| 97 | +``` |
| 98 | + |
| 99 | + |
| 100 | +## [GitLab Pipelines Basics](@/notes/20260602020259-gitlab_pipelines_basics.md) {#gitlab-pipelines-basics--20260602020259-gitlab-pipelines-basics-dot-md} |
0 commit comments