Skip to content

Commit b60257e

Browse files
committed
Github Actions
1 parent 91679f1 commit b60257e

4 files changed

Lines changed: 86 additions & 0 deletions

File tree

.DS_Store

4 KB
Binary file not shown.

.github/.DS_Store

6 KB
Binary file not shown.

.github/gitops-action/action.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: fleetctl-gitops
2+
description: Runs fleetctl gitops to apply configuration to Fleet
3+
4+
inputs:
5+
working-directory:
6+
description: 'The working directory, which should be the root of the fleet-gitops repository.'
7+
default: './'
8+
dry-run-only:
9+
description: 'Whether to only run the fleetctl gitops commands in dry-run mode.'
10+
default: 'false'
11+
delete-other-teams:
12+
description: 'Whether to delete other teams in Fleet which are not part of the gitops config.'
13+
default: 'true'
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Install fleetctl
19+
shell: bash
20+
working-directory: ${{ inputs.working-directory }}
21+
run: |
22+
FLEET_VERSION="$(curl "$FLEET_URL/api/v1/fleet/version" --header "Authorization: Bearer $FLEET_API_TOKEN" --fail --silent | jq --raw-output '.version')"
23+
24+
if [[ -n "$FLEET_VERSION" ]] ; then
25+
npm install -g "fleetctl@$FLEET_VERSION" || npm install -g fleetctl
26+
else
27+
echo "Failed to get Fleet version from $FLEET_URL, installing latest version of fleetctl"
28+
npm install -g fleetctl
29+
fi
30+
31+
- name: Configure fleetctl
32+
shell: bash
33+
working-directory: ${{ inputs.working-directory }}
34+
run: fleetctl config set --address ${{ env.FLEET_URL }} --token ${{ env.FLEET_API_TOKEN }}
35+
36+
- name: Run fleetctl gitops commands
37+
shell: bash
38+
working-directory: ${{ inputs.working-directory }}
39+
env:
40+
FLEET_DRY_RUN_ONLY: ${{ inputs.dry-run-only }}
41+
FLEET_DELETE_OTHER_TEAMS: ${{ inputs.delete-other-teams }}
42+
run: ./gitops.sh

.github/workflows/workflow.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Apply latest configuration to Fleet'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch: # allows manual triggering
9+
10+
# Prevent concurrent runs of this workflow.
11+
concurrency:
12+
group: ${{ github.workflow }}
13+
cancel-in-progress: false
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
# Limit permissions of GITHUB_TOKEN.
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
fleet-gitops:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout GitOps repository
28+
uses: actions/checkout@v4
29+
30+
- name: Apply latest configuration to Fleet
31+
uses: ./.github/gitops-action
32+
with:
33+
# Run GitOps in dry-run mode for pull requests.
34+
dry-run-only: ${{ github.event_name == 'pull_request' && 'true' || 'false' }}
35+
# Add FLEET_URL and FLEET_API_TOKEN to the repository secrets.
36+
# In addition, specify or add secrets for all the environment variables that are mentioned in the global/team YAML files.
37+
env:
38+
FLEET_URL: ${{ secrets.FLEET_URL }}
39+
FLEET_API_TOKEN: ${{ secrets.FLEET_API_TOKEN }}
40+
FLEET_GLOBAL_ENROLL_SECRET: ${{ secrets.FLEET_GLOBAL_ENROLL_SECRET }}
41+
FLEET_WORKSTATIONS_ENROLL_SECRET: ${{ secrets.FLEET_WORKSTATIONS_ENROLL_SECRET }}
42+
FLEET_WORKSTATIONS_CANARY_ENROLL_SECRET: ${{ secrets.FLEET_WORKSTATIONS_CANARY_ENROLL_SECRET }}
43+
FLEET_ENGINEERING_ENROLL_SECRET: ${{ secrets.FLEET_ENGINEERING_ENROLL_SECRET }}
44+
FLEET_NEW_HIRES_ENROLL_SECRET: ${{ secrets.FLEET_NEW_HIRES_ENROLL_SECRET }}

0 commit comments

Comments
 (0)