1- # GitHub Action for GitOps
1+ # 🚀 GitHub Action for GitOps
22
33This GitHub Action can be used for our GitOps workflow.
4- The GitHub Action will build and push the Docker image for your service and deploys the new version at our Kubernetes clusters.
4+ The GitHub Action will build and push the Docker image for your service and deploys the new version at your Kubernetes clusters.
55
66## Requirement
77
88When you want to use this GitHub Action your GitHub repository should have a ` dev ` and ` master ` / ` main ` branch and it should use tags for releases.
9- For the ` dev ` branch we will change the files specified under ` gitopsdev ` .
10- For the ` master ` / ` main ` branch we will change the files specified under ` gitopsstage ` .
11- For a new tag the files under ` gitopsprod ` will be used.
129
13- This GitOps setup (dev -> dev, master -> stage, tag -> prod) should be the default for all our repositories.
14- However, if you have a special case, you can leave ` gitopsdev ` , ` gitopsstage ` and ` gitopsprod ` undefined, then those steps will be skipped.
10+ - For the ` dev ` branch we will change the files specified under ` gitops-dev ` .
11+ - For the ` master ` / ` main ` branch we will change the files specified under ` gitops-stage ` .
12+ - For a new tag the files under ` gitops-prod ` will be used.
1513
16- ## Usage
14+ This GitOps setup should be the default for all your repositories.
15+ However, if you have a special case, you can leave ` gitops-dev ` , ` gitops-stage ` and ` gitops-prod ` undefined, then those steps will be skipped.
16+
17+ ## Usages
18+
19+ ### Build, Push and Deploy Docker Image
1720
1821``` yaml
19- name : Redbook CI/ CD
22+ name : CD
2023
2124on : [push]
2225
@@ -30,72 +33,96 @@ jobs:
3033 - name : Checkout
3134 uses : actions/checkout@v3
3235
33- # Checkout our GitHub Action for GitOps.
34- - uses : actions/checkout @v3
36+ - name : GitOps (build, push and deploy a new Docker image)
37+ uses : Staffbase/gitops-github-action @v3
3538 with :
36- repository : Staffbase/gitops-github-action
37- ref : v3
38- # It's important that you clone the repository into the .github/gitops path, because the GitHub Action has a hard dependency on this path.
39- path : .github/gitops
39+ docker-username : ${{ secrets.DOCKER_USERNAME }}
40+ docker-password : ${{ secrets.DOCKER_PASSWORD }}
41+ docker-image : private/diablo-redbook
42+ gitops-token : ${{ secrets.GITOPS_TOKEN }}
43+ gitops-dev : |-
44+ clusters/customization/dev/mothership/diablo-redbook/diablo-redbook-helm.yaml spec.template.spec.containers.redbook.image
45+ gitops-stage : |-
46+ clusters/customization/stage/mothership/diablo-redbook/diablo-redbook-helm.yaml spec.template.spec.containers.redbook.image
47+ gitops-prod : |-
48+ clusters/customization/prod/mothership/diablo-redbook/diablo-redbook-helm.yaml spec.template.spec.containers.redbook.image
49+ ` ` `
4050
41- # Run the GitOps GitHub Action which builds and push the Docker image and then updates the deployment in the repository.
42- - name : GitOps (build, push and deploy a new Docker image)
43- # Here we are referencing the cloned GitHub Action.
44- uses : ./.github/gitops
45- # The DOCKER_USERNAME, DOCKER_PASSWORD and GITOPS_TOKEN secrets are available as organization secret.
51+ ### Build and Push Docker Image
52+
53+ ` ` ` yaml
54+ name : CD
55+
56+ on : [push]
57+
58+ jobs :
59+ ci-cd :
60+ name : Build and Push
61+
62+ runs-on : ubuntu-20.04
63+
64+ steps :
65+ - name : Checkout
66+ uses : actions/checkout@v3
67+
68+ - name : GitOps (build and push a new Docker image)
69+ uses : Staffbase/gitops-github-action@v3
70+ with :
71+ docker-username : ${{ secrets.DOCKER_USERNAME }}
72+ docker-password : ${{ secrets.DOCKER_PASSWORD }}
73+ docker-image : private/diablo-redbook
74+ ` ` `
75+
76+ ### Deploy Docker Image
77+
78+ ` ` ` yaml
79+ name : CD
80+
81+ on : [push]
82+
83+ jobs :
84+ ci-cd :
85+ name : Deploy
86+
87+ runs-on : ubuntu-20.04
88+
89+ steps :
90+ - name : Checkout
91+ uses : actions/checkout@v3
92+
93+ - name : GitOps (deploy a new Docker image)
94+ uses : Staffbase/gitops-github-action@v3
4695 with :
47- dockerusername : ${{ secrets.DOCKER_USERNAME }}
48- dockerpassword : ${{ secrets.DOCKER_PASSWORD }}
49- # This is the name of the Docker image for your service.
50- dockerimage : private/diablo-redbook
51- # List of build-time variables
52- dockerbuildargs : |
53- "ARG1='one'"
54- "ARG2='two'"
55- # Sets the target stage to build
56- dockerbuildtarget : " runtime"
57- # The additional arguments you need to build the docker image
58- gitopstoken : ${{ secrets.GITOPS_TOKEN }}
59- # The gitopsdev, gitopsstage and gitopsprod values are used to specify which files including the YAML path which should be updated with the new image.
60- # ATTENTION 1: You must use |- to remove the final newline in the string, otherwise the GitHub Action will fail.
61- # ATTENTION 2: The file path must be relative to the root of the GitOps repository (default: Staffbase/mops).
62- gitopsdev : |-
96+ docker-image : private/diablo-redbook
97+ gitops-token : ${{ secrets.GITOPS_TOKEN }}
98+ gitops-dev : |-
6399 clusters/customization/dev/mothership/diablo-redbook/diablo-redbook-helm.yaml spec.template.spec.containers.redbook.image
64- gitopsstage : |-
100+ gitops-stage : |-
65101 clusters/customization/stage/mothership/diablo-redbook/diablo-redbook-helm.yaml spec.template.spec.containers.redbook.image
66- gitopsprod : |-
102+ gitops-prod : |-
67103 clusters/customization/prod/mothership/diablo-redbook/diablo-redbook-helm.yaml spec.template.spec.containers.redbook.image
68- # You can also update multiple file or multiple images in one file.
69- # The following example updates the Varnish image in the production cluster for main-de1 and main-us1. It also updates two images one is used for the init container and the other one for the normal container.
70- # gitopsprod: |-
71- # clusters/customization/prod/main-de1/mediaserver/varnish-helm.yaml spec.template.spec.initContainers.config.image
72- # clusters/customization/prod/main-de1/mediaserver/varnish-helm.yaml spec.template.spec.containers.varnish.image
73- # clusters/customization/prod/main-us1/mediaserver/varnish-helm.yaml spec.template.spec.initContainers.config.image
74- # clusters/customization/prod/main-us1/mediaserver/varnish-helm.yaml spec.template.spec.containers.varnish.image
75104` ` `
76105
77106## Inputs
78107
79- | Name | Description | Default |
80- | -------------------------------| -------------------------------------------------------------------------------------------------------------------------------| --------------------------|
81- | ` dockerenabled ` | Build and push the Docker Image | ` true ` |
82- | ` dockerregistry ` | Docker Registry | ` registry.staffbase.com ` |
83- | ` dockerimage ` | Docker Image | |
84- | ` dockerusername ` | Username for the Docker Registry | |
85- | ` dockerpassword ` | Password for the Docker Registry | |
86- | ` dockerfile ` | Dockerfile | ` ./Dockerfile ` |
87- | ` dockerbuildargs ` | List of build-time variables | |
88- | ` dockerbuildtarget ` | Sets the target stage to build like: "runtime" | |
89- | ` gitopsenabled ` | Update the manifest files in the GitOps repository | ` true ` |
90- | ` gitopsorganization ` | GitHub Organization for GitOps | ` Staffbase ` |
91- | ` gitopsrepository ` | GitHub Repository for GitOps | ` mops ` |
92- | ` gitopsuser ` | GitHub User for GitOps | ` Staffbot ` |
93- | ` gitopsemail ` | GitHub User for GitOps
| ` [email protected] ` | 94- | ` gitopstoken ` | GitHub Token for GitOps | |
95- | ` gitopsdev ` | Files which should be updated by the GitHub Action for DEV | |
96- | ` gitopsstage ` | Files which should be updated by the GitHub Action for STAGE | |
97- | ` gitopsprod ` | Files which should be updated by the GitHub Action for PROD | |
98- | ` workingdirectory ` | The directory in which the GitOps action should be executed. The dockerfile variable should be relative to working directory. | ` . ` |
108+ | Name | Description | Default |
109+ |-----------------------|--------------------------------------------------------------------------------------------------------------------------------|--------------------------|
110+ | ` docker-registry` | Docker Registry | `registry.staffbase.com` |
111+ | `docker-image` | Docker Image | |
112+ | `docker-username` | Username for the Docker Registry | |
113+ | `docker-password` | Password for the Docker Registry | |
114+ | `docker-file` | Dockerfile | `./Dockerfile` |
115+ | `docker-build-args` | List of build-time variables | |
116+ | `docker-build-target` | Sets the target stage to build like : " runtime" | |
117+ | `gitops-organization` | GitHub Organization for GitOps | `Staffbase` |
118+ | `gitops-repository` | GitHub Repository for GitOps | `mops` |
119+ | `gitops-user` | GitHub User for GitOps | `Staffbot` |
120+ | `gitops-email` | GitHub Email for GitOps | `[email protected] ` | 121+ | `gitops-token` | GitHub Token for GitOps | |
122+ | `gitops-dev` | Files which should be updated by the GitHub Action for DEV, must be relative to the root of the GitOps repository | |
123+ | `gitops-stage` | Files which should be updated by the GitHub Action for STAGE, must be relative to the root of the GitOps repository | |
124+ | `gitops-prod` | Files which should be updated by the GitHub Action for PROD, must be relative to the root of the GitOps repository | |
125+ | `working-directory` | The directory in which the GitOps action should be executed. The docker-file variable should be relative to working directory. | `.` |
99126
100127# # Contributing
101128
@@ -105,8 +132,6 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
105132
106133This project is licensed under the Apache-2.0 License - see the [LICENSE.md](LICENSE) file for details.
107134
108-
109-
110135<table>
111136 <tr>
112137 <td>
0 commit comments