-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding working GitHub action workflow (#26)
* Fixed configs. Currently working locally. * Updated workflow. * Updated GitHub action workflow. * Removed daily cron workflow schedule.
- Loading branch information
Showing
9 changed files
with
113 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,35 @@ | ||
name: 'Apply latest configuration profiles via Fleet' | ||
description: 'Applies the latest MDM configuration profiles to a Fleet team' | ||
|
||
inputs: | ||
FLEET_API_TOKEN: | ||
description: 'Fleet API Token' | ||
required: true | ||
FLEET_URL: | ||
description: 'Fleet URL' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: ${{ inputs.MDM_CONFIG_REPO }} | ||
|
||
- name: Install fleetctl | ||
run: npm install -g fleetctl | ||
shell: bash | ||
|
||
- name: Configure fleetctl | ||
run: fleetctl config set --address ${{ inputs.FLEET_URL }} --token ${{ inputs.FLEET_API_TOKEN }} | ||
shell: bash | ||
|
||
- name: Run fleetctl apply | ||
run: | | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# STEP 1: Apply config | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# Combine the contents of all the top-level config into a single YAML document | ||
# - Include the contents of no-team.controls.yml | ||
# TODO | ||
# - Include the contents of default.settings.yml | ||
# TODO | ||
# - Include anything of `kind: config` in default.queries.yml | ||
# TODO | ||
# - Include anything of `kind: config` in default.policies.yml | ||
# TODO | ||
# Apply top-level config with `--replace` (replaces all existing top-level config) | ||
# TODO | ||
# Loop through folders in /teams and combine the contents of all team config into a single YAML document | ||
# - Include the contents of <folder-name>.controls.yml | ||
# TODO | ||
# - Include the contents of <folder-name>.settings.yml | ||
# TODO | ||
# - Include anything of `kind: team` in <folder-name>.queries.yml | ||
# TODO | ||
# - Include anything of `kind: team` in <folder-name>.policies.yml | ||
# TODO | ||
# Apply team config with `--replace` (replaces all existing config for this team) | ||
# TODO | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# STEP 2: Apply queries | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# Compile all queries into a single YAML document | ||
# - Include anything of `kind: query` in default.queries.yml | ||
# TODO | ||
# - Loop through folders in /teams and include anything of `kind: query` in <folder-name>.queries.yml for each | ||
# TODO | ||
# Apply compiled queries YAML with `--replace` (deletes any queries in Fleet that aren't present in this config) | ||
# TODO | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# STEP 3: Apply policies | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# Compile all policies into a single YAML document | ||
# TODO | ||
# - Include anything of `kind: policy` in default.policies.yml | ||
# TODO | ||
# - Loop through folders in /teams and include anything of `kind: policy` in <folder-name>.policies.yml for each | ||
# TODO | ||
# Apply compiled policies YAML with `--replace` (deletes any policies in Fleet that aren't present in this config) | ||
# TODO | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
# All done! | ||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
shell: bash | ||
name: 'Apply latest configuration to Fleet' | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: # allows manual triggering | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
# Add FLEET_URL and FLEET_API_TOKEN to the repository secrets. | ||
# In addition, specify or add secrets for all the environment variables that are mentioned in the global/team YAML files. | ||
env: | ||
FLEET_SSO_METADATA: ${{ secrets.FLEET_SSO_METADATA }} | ||
FLEET_GLOBAL_ENROLL_SECRET: ${{ secrets.FLEET_GLOBAL_ENROLL_SECRET }} | ||
FLEET_WORKSTATIONS_ENROLL_SECRET: ${{ secrets.FLEET_WORKSTATIONS_ENROLL_SECRET }} | ||
FLEET_WORKSTATIONS_CANARY_ENROLL_SECRET: ${{ secrets.FLEET_WORKSTATIONS_CANARY_ENROLL_SECRET }} | ||
|
||
jobs: | ||
build-docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout GitOps repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install fleetctl | ||
run: npm install -g fleetctl | ||
|
||
- name: Configure fleetctl | ||
run: fleetctl config set --address ${{ secrets.FLEET_URL }} --token ${{ secrets.FLEET_API_TOKEN }} | ||
|
||
- name: Run fleetctl gitops commands | ||
run: ./workflow.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
# -e: Immediately exit if any command has a non-zero exit status. | ||
# -x: Print all executed commands to the terminal. | ||
# -u: Exit if an undefined variable is used. | ||
# -o pipefail: Exit if any command in a pipeline fails. | ||
set -exuo pipefail | ||
|
||
GLOBAL_FILE=./default.yml | ||
FLEETCTL="${FLEETCTL:-fleetctl}" | ||
|
||
# Validate that global file contains org_settings | ||
grep -Exq "^org_settings:.*" $GLOBAL_FILE | ||
|
||
if compgen -G ./teams/*.yml > /dev/null; then | ||
# Validate that every team has a unique name. | ||
# This is a limited check that assumes all team files contain the phrase: `name: <team_name>` | ||
! perl -nle 'print $1 if /^name:\s*(.+)$/' ./teams/*.yml | sort | uniq -d | grep . -cq | ||
fi | ||
|
||
# Dry run | ||
$FLEETCTL gitops -f $GLOBAL_FILE --dry-run | ||
for team_file in ./teams/*.yml; do | ||
$FLEETCTL gitops -f "$team_file" --dry-run | ||
done | ||
|
||
# Real run | ||
$FLEETCTL gitops -f $GLOBAL_FILE | ||
for team_file in ./teams/*.yml; do | ||
$FLEETCTL gitops -f "$team_file" | ||
done |