Skip to content

Commit 9719d84

Browse files
authored
Adding GitLab pipeline. (#48)
* Adding GitLab pipeline. * Fixing links
1 parent ffe156f commit 9719d84

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

.github/gitops-action/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ runs:
2222
FLEET_VERSION="$(curl "$FLEET_URL/api/v1/fleet/version" --header "Authorization: Bearer $FLEET_API_TOKEN" --fail --silent | jq --raw-output '.version')"
2323
2424
if [[ -n "$FLEET_VERSION" ]] ; then
25-
npm install -g "fleetctl@$FLEET_VERSION"
25+
npm install -g "fleetctl@$FLEET_VERSION" || npm install -g fleetctl
2626
else
2727
echo "Failed to get Fleet version from $FLEET_URL, installing latest version of fleetctl"
2828
npm install -g fleetctl

.gitlab-ci.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
fleet-gitops:
2+
image: node:22
3+
variables:
4+
FLEET_DRY_RUN_ONLY: true
5+
rules:
6+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
7+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
8+
variables:
9+
FLEET_DRY_RUN_ONLY: false
10+
before_script:
11+
- apt-get -qq update
12+
- apt-get install -y jq=1.6-2.1
13+
script:
14+
- >
15+
FLEET_VERSION="$(curl "$FLEET_URL/api/v1/fleet/version" --header "Authorization: Bearer $FLEET_API_TOKEN" --fail --silent | jq --raw-output '.version')"
16+
- >
17+
if [[ -n "$FLEET_VERSION" ]] ; then
18+
npm install -g "fleetctl@$FLEET_VERSION" || npm install -g fleetctl
19+
else
20+
echo "Failed to get Fleet version from $FLEET_URL, installing latest version of fleetctl"
21+
npm install -g fleetctl
22+
fi
23+
- fleetctl config set --address $FLEET_URL --token $FLEET_API_TOKEN
24+
- ./gitops.sh

README.md

+30-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,38 @@ How to set up your GitOps workflow:
1010

1111
3. Make any changes to policies, queries, controls, and more defined in the files.
1212

13-
4. Create your own GitHub repository.
13+
4. [Set up on GitHub](#set-up-on-github) or [set up on GitLab](#set-up-on-gitlab).
1414

15-
5. Add `FLEET_URL` and `FLEET_API_TOKEN` secrets to your new repository's secrets. Learn how [here](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository). Set `FLEET_URL` to your Fleet instance's URL (ex. https://organization.fleet.com). Set `FLEET_API_TOKEN` to an API token for an API-only user in Fleet. Learn how [here](https://fleetdm.com/docs/using-fleet/fleetctl-cli#create-api-only-user).
15+
## Set up on GitHub
1616

17-
6. Push your cloned and modified code to your repo.
17+
1. Create your own GitHub repository.
1818

19-
7. In GitHub, enable the `Apply latest configuration to Fleet` GitHub Actions workflow, and run workflow manually. Now, when anyone pushes a new commit, the action will run and update Fleet.
19+
2. Add `FLEET_URL` and `FLEET_API_TOKEN` secrets to your new repository's secrets. Learn how [here](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository). Set `FLEET_URL` to your Fleet instance's URL (ex. https://organization.fleet.com). Set `FLEET_API_TOKEN` to an API token for an API-only user in Fleet. Learn how [here](https://fleetdm.com/docs/using-fleet/fleetctl-cli#create-api-only-user).
20+
21+
3. Add `FLEET_GLOBAL_ENROLL_SECRET` secret to your new repository's secrets. The enroll secret must be an alphanumeric string of at least 32 and at most 255 characters.
22+
- If you have a Premium Fleet license, also add `FLEET_WORKSTATIONS_ENROLL_SECRET` and `FLEET_WORKSTATIONS_CANARY_ENROLL_SECRET`.
23+
24+
4. Delete `.gitlab-ci.yml`, which is for GitLab CI/CD.
25+
26+
5. Push your cloned and modified code to your repo.
27+
28+
6. In GitHub, enable the `Apply latest configuration to Fleet` GitHub Actions workflow, and run workflow manually. Now, when anyone pushes a new commit to the default branch, the action will run and update Fleet. For pull requests, the workflow will do a dry run only.
29+
30+
## Set up on GitLab
31+
32+
1. Create your own GitLab repository.
33+
34+
2. Add `FLEET_URL` and `FLEET_API_TOKEN` as masked CI/CD variables. Learn how [here](https://docs.gitlab.com/ee/ci/variables/#define-a-cicd-variable-in-the-ui). Set `FLEET_URL` to your Fleet instance's URL (ex. https://organization.fleet.com). Set `FLEET_API_TOKEN` to an API token for an API-only user in Fleet. Learn how [here](https://fleetdm.com/docs/using-fleet/fleetctl-cli#create-api-only-user).
35+
36+
3. Add `FLEET_GLOBAL_ENROLL_SECRET` secret as a masked CI/CD variable. The enroll secret must be an alphanumeric string of at least 32 and at most 255 characters.
37+
- If you have a Premium Fleet license, also add `FLEET_WORKSTATIONS_ENROLL_SECRET` and `FLEET_WORKSTATIONS_CANARY_ENROLL_SECRET`.
38+
39+
4. Delete `.github` folder, which is for GitHub Actions.
40+
41+
5. Push your cloned and modified code to your repo.
42+
43+
6. Now, when anyone pushes a new commit to the default branch, the pipeline will run and update Fleet. For merge requests, the pipeline will do a dry run only.
44+
45+
## Configuration options
2046

2147
For all configuration options, go to [GitOps reference](https://fleetdm.com/docs/using-fleet/gitops) in the Fleet documentation.

0 commit comments

Comments
 (0)