Skip to content

Commit dfc169a

Browse files
GavinHeffm-bullmaxstack
authored
Add linting Git workflow and local linting env (#11)
* Add linter config * Fix issues raised by linter * Update sample-appliance.yml Co-authored-by: Matt Anson <matta@stackhpc.com> * Update deprecated load_balancer resource * Fixes needed to run the sample appliance in an Azimuth dev env Fixed yaml lint issues after running superlint * Fix issues found by ansible-lint * Add handlers to load balancer roles --------- Co-authored-by: Matt Anson <matta@stackhpc.com> Co-authored-by: Max Norton <maxn@stackhpc.com>
1 parent a9bd7fa commit dfc169a

18 files changed

Lines changed: 246 additions & 89 deletions

File tree

.ansible-lint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
skip_list:
3+
- role-name
4+
5+
exclude_paths:
6+
- vendor/**
7+
- .github/**

.checkov.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
skip-check:
3+
# Requires all blocks to have rescue: - not considered appropriate
4+
- CKV2_ANSIBLE_3
5+
- CKV2_GHA_1
6+
skip-path:
7+
- vendor/
8+
- collections/

.github/linters/.checkov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.checkov.yml

.github/linters/.yamllint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.yamllint.yml
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Lint repository
2+
3+
on: # yamllint disable-line rule:truthy
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- ready_for_review
9+
- reopened
10+
branches:
11+
- main
12+
paths-ignore:
13+
# Ignore any changes that are not actually code changes
14+
- .gitignore
15+
- LICENSE
16+
17+
permissions:
18+
contents: read
19+
packages: write
20+
# To report GitHub Actions status checks
21+
statuses: write
22+
security-events: write
23+
id-token: write
24+
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.ref }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
lint:
31+
name: Lint
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
packages: read
36+
# To report GitHub Actions status checks
37+
statuses: write
38+
if: github.repository == 'azimuth-cloud/azimuth-sample-appliance'
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
# super-linter needs the full git history to get the
44+
# list of files that changed across commits
45+
fetch-depth: 0
46+
submodules: true
47+
48+
- name: Run ansible-lint
49+
uses: ansible/ansible-lint@v25.4.0
50+
51+
- name: Load super-linter configuration
52+
# Use grep inverse matching to exclude eventual comments in the .env file
53+
# because the GitHub Actions command to set environment variables doesn't
54+
# support comments.
55+
# yamllint disable-line rule:line-length
56+
# Ref: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
57+
if: always()
58+
run: grep -v '^#' super-linter.env >> "$GITHUB_ENV"
59+
60+
- name: Run super-linter
61+
uses: super-linter/super-linter@v7.3.0
62+
if: always()
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
VALIDATE_YAML: false

.yamllint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
brackets:
6+
forbid: non-empty
7+
comments:
8+
# https://github.com/prettier/prettier/issues/6780
9+
min-spaces-from-content: 1
10+
# https://github.com/adrienverge/yamllint/issues/384
11+
comments-indentation: false
12+
document-start: disable
13+
# 160 chars was the default used by old E204 rule, but
14+
# you can easily change it or disable in your .yamllint file.
15+
line-length:
16+
max: 160
17+
# We are adding an extra space inside braces as that's how prettier does it
18+
# and we are trying not to fight other linters.
19+
braces:
20+
min-spaces-inside: 0 # yamllint defaults to 0
21+
max-spaces-inside: 1 # yamllint defaults to 0
22+
octal-values:
23+
forbid-implicit-octal: true # yamllint defaults to false
24+
forbid-explicit-octal: true # yamllint defaults to false

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,23 @@ Azimuth user interface. These are controlled by the cluster metadata file.
9696

9797
The following system variables are provided by Azimuth:
9898

99+
<!-- markdownlint-disable -->
100+
99101
| Variable name | Description |
100102
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
101103
| `cluster_id` | The ID of the cluster. Should be used in the [Terraform state key](./group_vars/openstack.yml#L2). |
102104
| `cluster_name` | The name of the cluster as given by the user. |
103105
| `cluster_type` | The name of the cluster type. |
104106
| `cluster_user_ssh_public_key` | The SSH public key of the user that deployed the cluster. |
105107
| `cluster_deploy_ssh_public_key` | A cluster-specific SSH public key generated by the CaaS operator. |
106-
| `cluster_ssh_private_key_file` | The path to a file containing the private key corresponding to `cluster_deploy_ssh_public_key`.<br>This is consumed by the `azimuth_cloud.terraform.infra` role. |
108+
| `cluster_ssh_private_key_file` | The path to a file containing the private key corresponding to `cluster_deploy_ssh_public_key`.<br>This is consumed by the `azimuth_cloud.terraform.infra` role. |
107109
| `cluster_network` | The name of the project internal network onto which cluster nodes should be placed. |
108110
| `cluster_floating_network` | The name of the floating network where floating IPs can be allocated. |
109111
| `cluster_upgrade_system_packages` | This variable is set when a PATCH operation is requested.<br>If given and `true`, it indicates that system packages should be upgraded. If not given, it should be assumed to be `false`.<br>The mechanism for acheiving this is appliance-specific, but it is expected to be a disruptive operation (e.g. rebuilding nodes).<br>If not given or set to `false`, disruptive operations should be avoided where possible. |
110112
| `cluster_state` | This variable is set when a DELETE operation is requested.<br>If given and set to `absent` all cluster resources should be deleted, otherwise cluster resources should be updated as normal. |
111113

114+
<!-- markdownlint-enable -->
115+
112116
## Cluster metadata
113117

114118
Each CaaS appliance has a playbook (which may call other playbooks, roles, etc.) and a
@@ -182,3 +186,19 @@ To do this, just use a `debug` task with the variable `outputs` set to a diction
182186

183187
For example, this appliance
184188
[uses the cluster outputs to return the allocated floating IP](./sample-appliance.yml#L29-L34).
189+
190+
## Developing locally
191+
192+
Locally run the linters that are run in GitHub Actions using:
193+
194+
```sh
195+
docker run --rm \
196+
-e RUN_LOCAL=true \
197+
--env-file "super-linter.env" \
198+
-v "$(pwd)":/tmp/lint \
199+
ghcr.io/super-linter/super-linter:v7.3.0
200+
```
201+
202+
```sh
203+
ansible-lint -c .ansible-lint.yml ansible/
204+
```

group_vars/openstack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
# The default Terraform state key for backends that support it
23
terraform_state_key: "cluster/{{ cluster_id }}/tfstate"
34

requirements.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
collections:
23
- name: https://github.com/azimuth-cloud/ansible-collection-terraform
34
type: git

roles/backend/tasks/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
---
2-
32
- name: Ensure HTML directory exists
4-
file:
3+
ansible.builtin.file:
54
path: /opt/sample-appliance/html
65
state: directory
6+
mode: '0755'
77

88
- name: Install HTML index file
9-
template:
9+
ansible.builtin.template:
1010
src: index.html.j2
1111
dest: /opt/sample-appliance/html/index.html
12+
mode: '0644'
1213
register: html_index
1314

1415
- name: Install Nginx site config
15-
template:
16+
ansible.builtin.template:
1617
src: nginx.conf.j2
1718
dest: /etc/nginx/conf.d/sample-appliance.conf
19+
mode: '0644'
1820
register: nginx_conf
1921

2022
- name: Restart Nginx if required
21-
service:
23+
ansible.builtin.service:
2224
name: nginx
2325
state: restarted
2426
when: html_index is changed or nginx_conf is changed

0 commit comments

Comments
 (0)