@lekman/devops-toolkit-tasks 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @lekman/devops-toolkit-tasks
2
+
3
+ Six shared [Task](https://taskfile.dev) files for AI tooling, AWS, Docker, git,
4
+ module updates and container security scanning. Install once, include what you
5
+ need, and the same commands work across every repository.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ brew install go-task/tap/go-task # once per machine
11
+ npm i -D @lekman/devops-toolkit-tasks
12
+ ```
13
+
14
+ ## Use
15
+
16
+ Add the includes you want to `taskfile.yml` at your repository root:
17
+
18
+ ```yaml
19
+ version: "3"
20
+
21
+ includes:
22
+ ai: node_modules/@lekman/devops-toolkit-tasks/common/ai.yml
23
+ aws: node_modules/@lekman/devops-toolkit-tasks/common/aws.yml
24
+ docker: node_modules/@lekman/devops-toolkit-tasks/common/docker.yml
25
+ git: node_modules/@lekman/devops-toolkit-tasks/common/git.yml
26
+ modules: node_modules/@lekman/devops-toolkit-tasks/common/modules.yml
27
+ security: node_modules/@lekman/devops-toolkit-tasks/common/security.yml
28
+
29
+ tasks:
30
+ default:
31
+ silent: true
32
+ cmds:
33
+ - task --list
34
+ ```
35
+
36
+ Then `task --list` shows everything available, and each task is namespaced by
37
+ its include:
38
+
39
+ ```bash
40
+ task git:prune # delete merged local branches
41
+ task docker:build-image # build the image
42
+ task aws:check-auth # verify the current AWS session
43
+ ```
44
+
45
+ ## What each file provides
46
+
47
+ | Include | Tasks |
48
+ | ---------- | -------------------------------------------------------------------------------- |
49
+ | `ai` | `setup` — install and configure the AI tooling |
50
+ | `aws` | `check-auth`, `configure-docker`, `ensure-ecr-repository` |
51
+ | `docker` | `ensure-docker-running`, `build-image`, `tag-image`, `push-image` |
52
+ | `git` | `cd-root`, `get-root`, `prune`, `fetch-prune`, `switch-default`, `list-branches` |
53
+ | `modules` | `update-tools` — update the pinned toolchain |
54
+ | `security` | `scan-image` — container vulnerability scan |
55
+
56
+ Include only what a repository needs; an unused include costs nothing but adds
57
+ noise to `task --list`.
58
+
59
+ ## Requirements
60
+
61
+ `go-task` v3. Individual tasks may need the tool they wrap — the AWS tasks need
62
+ the AWS CLI, the Docker tasks need a running Docker daemon. Each task checks and
63
+ fails with a clear message rather than a stack trace.
64
+
65
+ ## Licence
66
+
67
+ MIT © Tobias Lekman
package/common/ai.yml ADDED
@@ -0,0 +1,106 @@
1
+ version: "3"
2
+
3
+ vars:
4
+ # Color codes for output
5
+ CYAN: '\033[0;36m'
6
+ GREEN: '\033[0;32m'
7
+ YELLOW: '\033[0;33m'
8
+ RED: '\033[0;31m'
9
+ NC: '\033[0m' # No Color
10
+
11
+ tasks:
12
+ # Setup AI development tools
13
+ setup:
14
+ desc: Setup AI development tools (Claude, Codex, Cursor, GitHub Copilot, Task Master)
15
+ silent: true
16
+ cmds:
17
+ - |
18
+ # Check if npm is installed
19
+ if ! command -v npm &> /dev/null; then
20
+ echo -e "{{.RED}}Error: npm is not installed{{.NC}}"
21
+ echo "Please install Node.js and npm first:"
22
+ echo " brew install node"
23
+ exit 1
24
+ fi
25
+
26
+ # Function to check and install npm package
27
+ check_and_install_npm() {
28
+ local package=$1
29
+ local version=$(npm list -g $package 2>/dev/null | grep $package || echo "")
30
+
31
+ if [ -z "$version" ]; then
32
+ echo -e "{{.CYAN}}Installing $package...{{.NC}}"
33
+ npm install -g $package --silent
34
+ else
35
+ echo -e "{{.CYAN}}Updating $package to latest version...{{.NC}}"
36
+ npm install -g $package@latest --silent
37
+ fi
38
+ }
39
+
40
+ # Install/Update npm packages
41
+ check_and_install_npm "@anthropic-ai/claude-code"
42
+ check_and_install_npm "@openai/codex"
43
+ check_and_install_npm "task-master-ai"
44
+
45
+ # Check if Cursor is installed
46
+ if [ ! -d "/Applications/Cursor.app" ]; then
47
+ echo -e "{{.CYAN}}Installing Cursor...{{.NC}}"
48
+ # Download and install Cursor
49
+ curl -L "https://download.cursor.sh/mac" -o /tmp/cursor.dmg
50
+ hdiutil attach /tmp/cursor.dmg
51
+ cp -R "/Volumes/Cursor/Cursor.app" /Applications/
52
+ hdiutil detach "/Volumes/Cursor"
53
+ rm /tmp/cursor.dmg
54
+ else
55
+ echo -e "{{.GREEN}}Cursor is already installed{{.NC}}"
56
+ echo -e "{{.YELLOW}}Note: Please check for updates manually in the Cursor app{{.NC}}"
57
+ fi
58
+
59
+ # Check if Cursor CLI is available
60
+ if ! command -v cursor &> /dev/null; then
61
+ echo -e "{{.YELLOW}}Note: Cursor CLI not found. Some extension management features may be limited.{{.NC}}"
62
+ echo "To enable CLI features, please:"
63
+ echo "1. Open Cursor"
64
+ echo "2. Go to Settings"
65
+ echo "3. Enable 'Install Command Line Tools'"
66
+ else
67
+ # Install GitHub Copilot extension
68
+ echo -e "{{.CYAN}}Installing GitHub Copilot extension...{{.NC}}"
69
+ cursor --install-extension GitHub.copilot --force > /dev/null 2>&1
70
+
71
+ # Check for workspace recommended extensions
72
+ if [ -d ".vscode" ] && [ -f ".vscode/extensions.json" ]; then
73
+ # Extract recommended extensions
74
+ recommended_extensions=$(jq -r '.recommendations[]' .vscode/extensions.json 2>/dev/null)
75
+
76
+ if [ ! -z "$recommended_extensions" ]; then
77
+ echo -e "{{.CYAN}}Found workspace recommended extensions:{{.NC}}"
78
+ echo "$recommended_extensions"
79
+
80
+ # Ask user if they want to install recommended extensions
81
+ echo -n "Do you want to install these workspace recommended extensions? (y/N) "
82
+ read answer
83
+
84
+ if [[ "$answer" =~ ^[Yy]$ ]]; then
85
+ echo -e "{{.CYAN}}Installing workspace recommended extensions...{{.NC}}"
86
+ for ext in $recommended_extensions; do
87
+ echo -e "{{.CYAN}}Installing $ext...{{.NC}}"
88
+ cursor --install-extension "$ext" --force > /dev/null 2>&1
89
+ done
90
+ echo -e "{{.GREEN}}Workspace recommended extensions installed!{{.NC}}"
91
+ else
92
+ echo -e "{{.YELLOW}}Skipping workspace recommended extensions.{{.NC}}"
93
+ fi
94
+ else
95
+ echo -e "{{.YELLOW}}No recommended extensions found in workspace.{{.NC}}"
96
+ fi
97
+ fi
98
+ fi
99
+
100
+ echo -e "{{.GREEN}}AI development tools setup complete!{{.NC}}"
101
+ echo -e "{{.YELLOW}}Note: Some tools may require additional configuration:{{.NC}}"
102
+ echo "1. Cursor: Sign in to your account"
103
+ echo "2. GitHub Copilot: Sign in to your GitHub account in Cursor"
104
+ echo "3. Claude Code: Configure your API key"
105
+ echo "4. OpenAI Codex: Configure your API key"
106
+ echo "5. Task Master: Configure your API key"
package/common/aws.yml ADDED
@@ -0,0 +1,41 @@
1
+ version: "3"
2
+
3
+ vars:
4
+ AWS_REGION: '{{.AWS_REGION | default "eu-north-1"}}'
5
+ AWS_PROFILE: '{{.AWS_PROFILE | default "web.development"}}'
6
+ ECR_REGISTRY: '{{.ECR_REGISTRY | default "066281862119.dkr.ecr.eu-north-1.amazonaws.com/secnord/shared-images"}}'
7
+
8
+ tasks:
9
+ # Check AWS authentication
10
+ check-auth:
11
+ desc: Check AWS authentication
12
+ silent: true
13
+ cmds:
14
+ - aws sts get-caller-identity --profile {{.AWS_PROFILE}} --no-cli-pager
15
+
16
+ # Configure Docker to use AWS credentials
17
+ configure-docker:
18
+ desc: Configure Docker to use AWS credentials
19
+ silent: true
20
+ cmds:
21
+ - |
22
+ if [ ! -f ~/.docker/config.json ]; then
23
+ mkdir -p ~/.docker
24
+ echo '{"credsStore": "ecr-login"}' > ~/.docker/config.json
25
+ fi
26
+ - aws ecr get-login-password --region {{.AWS_REGION}} --profile {{.AWS_PROFILE}} --no-cli-pager | docker login --username AWS --password-stdin {{.ECR_REGISTRY}}
27
+
28
+ # Create ECR repository if it doesn't exist
29
+ ensure-ecr-repository:
30
+ desc: Ensure ECR repository exists
31
+ silent: true
32
+ vars:
33
+ REPOSITORY_NAME: "{{.REPOSITORY_NAME}}"
34
+ cmds:
35
+ - |
36
+ if ! aws ecr describe-repositories --repository-names "{{.REPOSITORY_NAME}}" --region {{.AWS_REGION}} --profile {{.AWS_PROFILE}} --no-cli-pager >/dev/null 2>&1; then
37
+ echo "Creating ECR repository {{.REPOSITORY_NAME}}..."
38
+ aws ecr create-repository --repository-name "{{.REPOSITORY_NAME}}" --region {{.AWS_REGION}} --profile {{.AWS_PROFILE}} --no-cli-pager
39
+ else
40
+ echo "ECR repository {{.REPOSITORY_NAME}} already exists"
41
+ fi
@@ -0,0 +1,68 @@
1
+ version: "3"
2
+
3
+ vars:
4
+ DOCKER_SOCKET: /var/run/docker.sock
5
+
6
+ tasks:
7
+ # Check if Docker is running and start it if needed
8
+ ensure-docker-running:
9
+ desc: Ensure Docker daemon is running
10
+ silent: true
11
+ cmds:
12
+ - |
13
+ if ! docker info >/dev/null 2>&1; then
14
+ echo "Docker is not running. Starting Docker..."
15
+ open -a Docker
16
+ # Wait for Docker to start
17
+ while ! docker info >/dev/null 2>&1; do
18
+ echo "Waiting for Docker to start..."
19
+ sleep 2
20
+ done
21
+ echo "Docker is now running"
22
+ fi
23
+
24
+ # Build a Docker image
25
+ build-image:
26
+ desc: Build a Docker image
27
+ silent: true
28
+ vars:
29
+ IMAGE_NAME:
30
+ sh: echo "{{.IMAGE_NAME}}"
31
+ IMAGE_TAG:
32
+ sh: echo "{{.IMAGE_TAG}}"
33
+ DOCKERFILE_PATH:
34
+ sh: echo "{{.DOCKERFILE_PATH}}"
35
+ cmds:
36
+ - task: ensure-docker-running
37
+ - echo "Building image {{.IMAGE_NAME}}:{{.IMAGE_TAG}} from {{.DOCKERFILE_PATH}}"
38
+ - docker build -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}} {{.DOCKERFILE_PATH}}
39
+
40
+ # Tag a Docker image
41
+ tag-image:
42
+ desc: Tag a Docker image
43
+ silent: true
44
+ vars:
45
+ SOURCE_IMAGE:
46
+ sh: echo "{{.SOURCE_IMAGE}}"
47
+ SOURCE_TAG:
48
+ sh: echo "{{.SOURCE_TAG}}"
49
+ TARGET_IMAGE:
50
+ sh: echo "{{.TARGET_IMAGE}}"
51
+ TARGET_TAG:
52
+ sh: echo "{{.TARGET_TAG}}"
53
+ cmds:
54
+ - echo "Tagging image {{.SOURCE_IMAGE}}:{{.SOURCE_TAG}} as {{.TARGET_IMAGE}}:{{.TARGET_TAG}}"
55
+ - docker tag {{.SOURCE_IMAGE}}:{{.SOURCE_TAG}} {{.TARGET_IMAGE}}:{{.TARGET_TAG}}
56
+
57
+ # Push a Docker image
58
+ push-image:
59
+ desc: Push a Docker image to registry
60
+ silent: true
61
+ vars:
62
+ IMAGE_NAME:
63
+ sh: echo "{{.IMAGE_NAME}}"
64
+ IMAGE_TAG:
65
+ sh: echo "{{.IMAGE_TAG}}"
66
+ cmds:
67
+ - echo "Pushing image {{.IMAGE_NAME}}:{{.IMAGE_TAG}}"
68
+ - docker push {{.IMAGE_NAME}}:{{.IMAGE_TAG}}
package/common/git.yml ADDED
@@ -0,0 +1,295 @@
1
+ version: "3"
2
+
3
+ vars:
4
+ # Color codes for output
5
+ CYAN: '\033[0;36m'
6
+ GREEN: '\033[0;32m'
7
+ YELLOW: '\033[0;33m'
8
+ RED: '\033[0;31m'
9
+ NC: '\033[0m' # No Color
10
+ # Valid workflow statuses
11
+ VALID_STATUSES: "queued completed in_progress requested waiting action_required cancelled failure neutral skipped stale startup_failure success timed_out"
12
+
13
+ tasks:
14
+ # Change to repository root
15
+ cd-root:
16
+ desc: Change to the repository root directory
17
+ silent: true
18
+ cmds:
19
+ - |
20
+ ROOT_DIR=$(git rev-parse --show-toplevel)
21
+ if [ -z "$ROOT_DIR" ]; then
22
+ echo "Error: Not in a git repository"
23
+ exit 1
24
+ fi
25
+ cd "$ROOT_DIR"
26
+
27
+ # Get repository root path
28
+ get-root:
29
+ desc: Get the absolute path to the repository root
30
+ silent: true
31
+ cmds:
32
+ - |
33
+ ROOT_DIR=$(git rev-parse --show-toplevel)
34
+ if [ -z "$ROOT_DIR" ]; then
35
+ echo "Error: Not in a git repository"
36
+ exit 1
37
+ fi
38
+ echo "$ROOT_DIR"
39
+
40
+ # Delete local branches that don't have a remote counterpart
41
+ prune:
42
+ desc: Delete local branches that don't have a remote counterpart
43
+ silent: true
44
+ vars:
45
+ BASE_DIR: '{{.BASE_DIR | default "."}}'
46
+ cmds:
47
+ - |
48
+ # Find all .git directories and iterate over them
49
+ find "{{.BASE_DIR}}" -type d -name ".git" | while read -r git_dir; do
50
+ # Get the parent directory of the .git folder
51
+ repo_dir=$(dirname "$git_dir")
52
+
53
+ echo -e "{{.CYAN}}Processing:{{.NC}} $repo_dir"
54
+
55
+ # Navigate to the repository directory
56
+ cd "$repo_dir" || {
57
+ echo "Failed to navigate to $repo_dir. Skipping."
58
+ continue
59
+ }
60
+
61
+ # Get the default branch name
62
+ default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
63
+
64
+ # Switch to the default branch
65
+ git checkout "$default_branch" >/dev/null 2>&1
66
+ git fetch -p >/dev/null 2>&1
67
+
68
+ # Fetch local branches that are gone on remote
69
+ git branch -vv | grep ': gone]' | while read -r line; do
70
+ # Remove the leading star if present
71
+ branch=$(echo "$line" | sed 's/^\* //;s/^[[:space:]]*//;s/[[:space:]]*$//' | cut -d ' ' -f 1)
72
+ echo -e "{{.RED}}Branch to delete: $branch{{.NC}}"
73
+ git branch -D "$branch"
74
+ done
75
+
76
+ echo -e "{{.GREEN}}Done{{.NC}}"
77
+
78
+ cd "$OLDPWD" || {
79
+ echo "Failed to navigate back. Exiting."
80
+ exit 1
81
+ }
82
+ done
83
+
84
+ echo "All repositories processed."
85
+ aliases: [clean-branches, clb]
86
+
87
+ # Fetch and prune remote branches
88
+ fetch-prune:
89
+ desc: Fetch and prune remote branches
90
+ silent: true
91
+ cmds:
92
+ - git fetch -p
93
+ aliases: [fp]
94
+
95
+ # Switch to default branch
96
+ switch-default:
97
+ desc: Switch to the default branch
98
+ silent: true
99
+ cmds:
100
+ - |
101
+ default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
102
+ git checkout "$default_branch"
103
+ aliases: [sd]
104
+
105
+ # List all branches
106
+ list-branches:
107
+ desc: List all branches with their status
108
+ silent: true
109
+ cmds:
110
+ - git --no-pager branch -vv
111
+ aliases: [lb]
112
+
113
+ # Delete GitHub workflow runs
114
+ delete-runs:
115
+ desc: Delete GitHub workflow runs for a branch with specific status
116
+ silent: true
117
+ vars:
118
+ BRANCH: '{{.BRANCH | default ""}}'
119
+ STATUS: '{{.STATUS | default "failure"}}'
120
+ cmds:
121
+ - |
122
+ # Check if gh CLI is installed
123
+ if ! command -v gh &> /dev/null; then
124
+ echo -e "{{.RED}}GitHub CLI (gh) is not installed{{.NC}}"
125
+ echo "Please install it first:"
126
+ echo " brew install gh"
127
+ echo "Then authenticate:"
128
+ echo " gh auth login"
129
+ exit 1
130
+ fi
131
+
132
+ # Check if authenticated with GitHub
133
+ if ! gh auth status &> /dev/null; then
134
+ echo -e "{{.RED}}Not authenticated with GitHub{{.NC}}"
135
+ echo "Please run:"
136
+ echo " gh auth login"
137
+ exit 1
138
+ fi
139
+
140
+ # Validate status
141
+ if [[ ! "{{.VALID_STATUSES}}" =~ {{.STATUS}} ]]; then
142
+ echo -e "{{.RED}}Invalid status: {{.STATUS}}{{.NC}}"
143
+ echo "Use one of:"
144
+ echo " {{.VALID_STATUSES}}"
145
+ exit 1
146
+ fi
147
+
148
+ # Get repository info from GitHub
149
+ repo_owner=$(gh repo view --json owner --jq '.owner.login')
150
+ repo_name=$(gh repo view --json name --jq '.name')
151
+
152
+ # If no branch specified, use current branch
153
+ branch="{{.BRANCH}}"
154
+ if [ -z "$branch" ]; then
155
+ branch=$(git rev-parse --abbrev-ref HEAD)
156
+ fi
157
+
158
+ echo -e "{{.CYAN}}Using repository: $repo_owner/$repo_name{{.NC}}"
159
+
160
+ # Handle all branches case
161
+ if [ "$branch" == "all" ] || [ "$branch" == "-all" ] || [ "$branch" == "--all" ] || [ "$branch" == "-a" ]; then
162
+ echo -e "{{.CYAN}}Processing runs in all branches...{{.NC}}"
163
+ workflow_runs=$(gh run list -R "$repo_owner/$repo_name" -a -s {{.STATUS}} --limit 100 --json databaseId)
164
+ else
165
+ echo -e "{{.CYAN}}Processing runs in branch $branch...{{.NC}}"
166
+ workflow_runs=$(gh run list -R "$repo_owner/$repo_name" -b "$branch" -a -s {{.STATUS}} --limit 100 --json databaseId)
167
+ fi
168
+
169
+ # Parse and delete runs
170
+ run_ids=$(echo "$workflow_runs" | jq -r '.[].databaseId')
171
+ deleted=0
172
+ for run_id in $run_ids; do
173
+ gh run delete $run_id
174
+ deleted=$((deleted+1))
175
+ done
176
+
177
+ # Report results
178
+ if [ $deleted -eq 0 ]; then
179
+ echo -e "{{.YELLOW}}No runs found with status {{.STATUS}} in branch $branch{{.NC}}"
180
+ else
181
+ echo -e "{{.GREEN}}Deleted $deleted runs with status {{.STATUS}} in branch $branch{{.NC}}"
182
+ fi
183
+ aliases: [dr]
184
+
185
+ # Git hooks management
186
+ hooks:setup:
187
+ desc: Set up git hooks with Jira integration
188
+ silent: true
189
+ vars:
190
+ JIRA_KEY: '{{.JIRA_KEY | default ""}}'
191
+ cmds:
192
+ - |
193
+ # Check if git is installed
194
+ if ! command -v git &> /dev/null; then
195
+ echo -e "{{.RED}}Error: Git CLI tools are missing. Please install them before running this script.{{.NC}}"
196
+ exit 1
197
+ fi
198
+
199
+ # Check if .git directory exists
200
+ if [ ! -d ".git" ]; then
201
+ echo -e "{{.RED}}Error: This script must be run from the workspace root folder.{{.NC}}"
202
+ exit 1
203
+ fi
204
+
205
+ # Get Jira key if not provided
206
+ jira_key="{{.JIRA_KEY}}"
207
+ if [ -z "$jira_key" ]; then
208
+ echo -e "{{.CYAN}}Please enter the Jira project key:{{.NC}}"
209
+ read jira_key
210
+ fi
211
+
212
+ # Validate Jira key
213
+ if [[ ! $jira_key =~ ^[a-zA-Z0-9]+$ ]]; then
214
+ echo -e "{{.RED}}Error: Jira project key must be alphanumeric.{{.NC}}"
215
+ exit 1
216
+ fi
217
+
218
+ echo -e "{{.CYAN}}Jira key: $jira_key{{.NC}}"
219
+ echo -e "{{.CYAN}}Configuring Jira Smart Commit git hooks...{{.NC}}"
220
+
221
+ # Create prepare-commit-msg hook from template
222
+ sed "s/JIRA_KEY_PLACEHOLDER/$jira_key/g" tasks/common/templates/prepare-commit-msg.template > .git/hooks/prepare-commit-msg
223
+
224
+ # Configure git to use the hooks
225
+ git config --local core.hooksPath .git/hooks/
226
+
227
+ # Make sure the script is executable
228
+ chmod +x .git/hooks/prepare-commit-msg
229
+
230
+ echo -e "{{.GREEN}}Git hooks configured.{{.NC}}"
231
+ aliases: [hs]
232
+
233
+ hooks:remove:
234
+ desc: Remove git hooks configuration
235
+ silent: true
236
+ cmds:
237
+ - |
238
+ # Check if git is installed
239
+ if ! command -v git &> /dev/null; then
240
+ echo -e "{{.RED}}Error: Git CLI tools are missing. Please install them before running this script.{{.NC}}"
241
+ exit 1
242
+ fi
243
+
244
+ # Check if .git directory exists
245
+ if [ ! -d ".git" ]; then
246
+ echo -e "{{.RED}}Error: This script must be run from the workspace root folder.{{.NC}}"
247
+ exit 1
248
+ fi
249
+
250
+ # Remove prepare-commit-msg hook
251
+ rm -f .git/hooks/prepare-commit-msg
252
+
253
+ # Reset git hooks path
254
+ git config --local --unset core.hooksPath
255
+
256
+ echo -e "{{.GREEN}}Git hooks removed.{{.NC}}"
257
+ aliases: [hr]
258
+
259
+ hooks:status:
260
+ desc: Show git hooks configuration status
261
+ silent: true
262
+ cmds:
263
+ - |
264
+ # Check if git is installed
265
+ if ! command -v git &> /dev/null; then
266
+ echo -e "{{.RED}}Error: Git CLI tools are missing. Please install them before running this script.{{.NC}}"
267
+ exit 1
268
+ fi
269
+
270
+ # Check if .git directory exists
271
+ if [ ! -d ".git" ]; then
272
+ echo -e "{{.RED}}Error: This script must be run from the workspace root folder.{{.NC}}"
273
+ exit 1
274
+ fi
275
+
276
+ echo -e "{{.CYAN}}Git hooks status:{{.NC}}"
277
+
278
+ # Check if prepare-commit-msg hook exists
279
+ if [ -f ".git/hooks/prepare-commit-msg" ]; then
280
+ echo -e "{{.GREEN}}✓ prepare-commit-msg hook is installed{{.NC}}"
281
+ # Show Jira project key
282
+ jira_key=$(grep "JIRA_PROJECT_KEY=" .git/hooks/prepare-commit-msg | cut -d"'" -f2)
283
+ echo -e "{{.CYAN}} Jira project key: $jira_key{{.NC}}"
284
+ else
285
+ echo -e "{{.YELLOW}}✗ prepare-commit-msg hook is not installed{{.NC}}"
286
+ fi
287
+
288
+ # Check git hooks path configuration
289
+ hooks_path=$(git config --local core.hooksPath)
290
+ if [ -n "$hooks_path" ]; then
291
+ echo -e "{{.GREEN}}✓ Git hooks path is configured: $hooks_path{{.NC}}"
292
+ else
293
+ echo -e "{{.YELLOW}}✗ Git hooks path is not configured{{.NC}}"
294
+ fi
295
+ aliases: [hst]
@@ -0,0 +1,41 @@
1
+ version: "3"
2
+
3
+ vars:
4
+ # Color codes for output
5
+ CYAN: '\033[0;36m'
6
+ GREEN: '\033[0;32m'
7
+ YELLOW: '\033[0;33m'
8
+ RED: '\033[0;31m'
9
+ NC: '\033[0m' # No Color
10
+
11
+ tasks:
12
+ # Update shared tools to latest version
13
+ update-tools:
14
+ desc: Update @lekman/devops-toolkit-tasks to the latest version
15
+ silent: true
16
+ cmds:
17
+ - |
18
+ # Get repository root
19
+ ROOT_DIR=$(git rev-parse --show-toplevel)
20
+ if [ -z "$ROOT_DIR" ]; then
21
+ echo -e "{{.YELLOW}}Warning: Not in a git repository{{.NC}}"
22
+ exit 0
23
+ fi
24
+ cd "$ROOT_DIR"
25
+
26
+ # Check if package.json exists
27
+ if [ ! -f "package.json" ]; then
28
+ echo -e "{{.YELLOW}}Warning: No package.json found in repository root{{.NC}}"
29
+ exit 0
30
+ fi
31
+
32
+ # Check if @lekman/devops-toolkit-tasks is in package.json
33
+ if ! grep -q "@lekman/devops-toolkit-tasks" package.json; then
34
+ echo -e "{{.YELLOW}}Warning: @lekman/devops-toolkit-tasks not found in package.json{{.NC}}"
35
+ exit 0
36
+ fi
37
+
38
+ echo -e "{{.CYAN}}Updating @lekman/devops-toolkit-tasks to latest version...{{.NC}}"
39
+ npm install --save-dev @lekman/devops-toolkit-tasks@latest
40
+ echo -e "{{.GREEN}}Update complete{{.NC}}"
41
+ aliases: [ut]
@@ -0,0 +1,22 @@
1
+ version: "3"
2
+
3
+ vars:
4
+ DOCKER_SOCKET: /var/run/docker.sock
5
+ TRIVY_IMAGE: aquasec/trivy:latest
6
+ DEFAULT_SEVERITY: "HIGH,CRITICAL"
7
+
8
+ tasks:
9
+ # Scan a Docker image for vulnerabilities
10
+ scan-image:
11
+ desc: Scan a Docker image for vulnerabilities using Trivy
12
+ silent: true
13
+ vars:
14
+ IMAGE_NAME:
15
+ sh: echo "{{.IMAGE_NAME}}"
16
+ IMAGE_TAG:
17
+ sh: echo "{{.IMAGE_TAG}}"
18
+ SEVERITY:
19
+ sh: echo "{{.SEVERITY | default .DEFAULT_SEVERITY}}"
20
+ cmds:
21
+ - echo "Scanning image {{.IMAGE_NAME}}:{{.IMAGE_TAG}} for {{.SEVERITY}} vulnerabilities"
22
+ - docker run -v {{.DOCKER_SOCKET}}:{{.DOCKER_SOCKET}} {{.TRIVY_IMAGE}} image --severity {{.SEVERITY}} {{.IMAGE_NAME}}:{{.IMAGE_TAG}}
package/docs/README.md ADDED
@@ -0,0 +1,238 @@
1
+ # DevOps Toolkit Tasks
2
+
3
+ A collection of reusable task modules for common DevOps operations, built with [GoTask](https://taskfile.dev/). These modules provide a standardized way to perform common operations across different projects.
4
+
5
+ ## Purpose
6
+
7
+ These task modules are designed to streamline common DevOps operations by providing:
8
+
9
+ - Standardized commands for common operations
10
+ - Consistent behavior across different projects
11
+ - Reusable components that can be shared between projects
12
+ - Simplified automation of routine tasks
13
+
14
+ The modules cover various aspects of development workflow including:
15
+
16
+ - AWS operations (ECR, authentication)
17
+ - Docker operations (build, tag, push)
18
+ - Git operations (branch management, hooks)
19
+ - Security scanning
20
+ - Module management
21
+
22
+ ## Installation
23
+
24
+ 1. Base `gotask` install
25
+
26
+ You only need to install `gotask` once on your machine.
27
+
28
+ ```bash
29
+ brew install go-task/tap/go-task
30
+ ```
31
+
32
+ 2. Install the shared tasks package (published on npmjs.org, no auth needed):
33
+
34
+ ```bash
35
+ npm i -D @lekman/devops-toolkit-tasks@latest
36
+ ```
37
+
38
+ 3. Set up your taskfile.yml
39
+
40
+ To use these tasks in your project, you can import the libaries in your `taskfile.yml` added to the root of your project:
41
+
42
+ The basic taskfile should look like this:
43
+
44
+ ```yaml
45
+ version: "3"
46
+
47
+ includes:
48
+ ai: node_modules/@lekman/devops-toolkit-tasks/common/ai.yml
49
+ aws: node_modules/@lekman/devops-toolkit-tasks/common/aws.yml
50
+ docker: node_modules/@lekman/devops-toolkit-tasks/common/docker.yml
51
+ git: node_modules/@lekman/devops-toolkit-tasks/common/git.yml
52
+ modules: node_modules/@lekman/devops-toolkit-tasks/common/modules.yml
53
+ security: node_modules/@lekman/devops-toolkit-tasks/common/security.yml
54
+
55
+ tasks:
56
+ # Default task that shows available commands
57
+ default:
58
+ silent: true
59
+ cmds:
60
+ - task --list
61
+ ```
62
+
63
+ ## Available Tasks
64
+
65
+ ### AI Tasks
66
+
67
+ | Task | Description | Alias |
68
+ | ---------- | ------------------------------------------------------------------------------- | ----- |
69
+ | `ai:setup` | Setup AI development tools (Claude, Codex, Cursor, GitHub Copilot, Task Master) | - |
70
+
71
+ ### AWS Tasks
72
+
73
+ | Task | Description | Alias |
74
+ | --------------------------- | ----------------------------------------- | ----- |
75
+ | `aws:check-auth` | Check AWS authentication | - |
76
+ | `aws:configure-docker` | Configure Docker to use AWS credentials | - |
77
+ | `aws:ensure-ecr-repository` | Create ECR repository if it doesn't exist | - |
78
+
79
+ ### Docker Tasks
80
+
81
+ | Task | Description | Alias |
82
+ | ------------------------------ | ------------------------------------------------- | ----- |
83
+ | `docker:ensure-docker-running` | Check if Docker is running and start it if needed | - |
84
+ | `docker:build-image` | Build a Docker image | - |
85
+ | `docker:tag-image` | Tag a Docker image | - |
86
+ | `docker:push-image` | Push a Docker image to registry | - |
87
+
88
+ ### Git Tasks
89
+
90
+ | Task | Description | Alias |
91
+ | -------------------- | ------------------------------------------------------------- | ------------------------------- |
92
+ | `git:cd-root` | Change to the repository root directory | - |
93
+ | `git:get-root` | Get the absolute path to the repository root | - |
94
+ | `git:prune` | Delete local branches that don't have a remote counterpart | `git:clean-branches`, `git:clb` |
95
+ | `git:fetch-prune` | Fetch and prune remote branches | `git:fp` |
96
+ | `git:switch-default` | Switch to the default branch | `git:sd` |
97
+ | `git:list-branches` | List all branches with their status | `git:lb` |
98
+ | `git:delete-runs` | Delete GitHub workflow runs for a branch with specific status | `git:dr` |
99
+ | `git:hooks:setup` | Set up git hooks with Jira integration | `git:hs` |
100
+ | `git:hooks:remove` | Remove git hooks configuration | `git:hr` |
101
+ | `git:hooks:status` | Show git hooks configuration status | `git:hst` |
102
+
103
+ ### Module Tasks
104
+
105
+ | Task | Description | Alias |
106
+ | ---------------------- | --------------------------------------------------------- | ------------ |
107
+ | `modules:update-tools` | Update @lekman/devops-toolkit-tasks to the latest version | `modules:ut` |
108
+
109
+ ### Security Tasks
110
+
111
+ | Task | Description | Alias |
112
+ | --------------------- | --------------------------------------------------- | ----- |
113
+ | `security:scan-image` | Scan a Docker image for vulnerabilities using Trivy | - |
114
+
115
+ ## Creating Custom Tasks
116
+
117
+ You can create custom tasks that depend on shared tasks and add your own logic. Here's an example of how to create a custom task that:
118
+
119
+ 1. Ensures Docker is running (using shared task)
120
+ 2. Performs custom logic
121
+ 3. Uses another shared task
122
+
123
+ ```yaml
124
+ version: "3"
125
+
126
+ includes:
127
+ docker: node_modules/@lekman/devops-toolkit-tasks/common/docker.yml
128
+ security: node_modules/@lekman/devops-toolkit-tasks/common/security.yml
129
+
130
+ tasks:
131
+ # Custom task that builds and scans an image
132
+ build-and-scan:
133
+ desc: Build a Docker image and scan it for vulnerabilities
134
+ silent: true # Reduces noise in output, only shows important messages
135
+ deps: [docker:ensure-docker-running] # Ensure Docker is running first
136
+ vars:
137
+ IMAGE_NAME: "{{.IMAGE_NAME}}"
138
+ IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}'
139
+ DOCKERFILE_PATH: '{{.DOCKERFILE_PATH | default "."}}'
140
+ cmds:
141
+ # Custom build logic
142
+ - echo "Building custom image..."
143
+ - docker build -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}} {{.DOCKERFILE_PATH}}
144
+
145
+ # Run security scan using shared task
146
+ - task: security:scan-image
147
+ vars:
148
+ IMAGE_NAME: "{{.IMAGE_NAME}}"
149
+ IMAGE_TAG: "{{.IMAGE_TAG}}"
150
+ SEVERITY: "HIGH,CRITICAL"
151
+ ```
152
+
153
+ You can run this custom task with:
154
+
155
+ ```bash
156
+ task build-and-scan IMAGE_NAME=myapp IMAGE_TAG=v1.0 DOCKERFILE_PATH=./docker
157
+ ```
158
+
159
+ The task will:
160
+
161
+ 1. First ensure Docker is running (using the shared `docker:ensure-docker-running` task)
162
+ 2. Execute the custom build commands
163
+ 3. Run the security scan using the shared `security:scan-image` task
164
+
165
+ This pattern allows you to:
166
+
167
+ - Reuse existing functionality from shared tasks
168
+ - Add your own custom logic
169
+ - Ensure proper task dependencies
170
+ - Keep your taskfile DRY (Don't Repeat Yourself)
171
+
172
+ ### Best Practices
173
+
174
+ #### Using the Silent Flag
175
+
176
+ The `silent: true` flag is a best practice for several reasons:
177
+
178
+ 1. **Cleaner Output**: It reduces noise in the terminal by hiding the command being executed, showing only the actual output
179
+ 2. **Better Readability**: Makes it easier to spot important messages and errors
180
+ 3. **Consistent Experience**: When chaining multiple tasks, it prevents command echo from each task
181
+ 4. **Professional Look**: The output looks more polished and professional
182
+ 5. **Easier Debugging**: When something goes wrong, the error messages stand out more clearly
183
+
184
+ You can still see the full command output by running the task with the `--verbose` flag:
185
+
186
+ ```bash
187
+ task build-and-scan --verbose
188
+ ```
189
+
190
+ This is particularly useful when debugging or when you need to see exactly what commands are being executed.
191
+
192
+ ### Task Organization
193
+
194
+ - **Keep it Modular**: Use separate task files for different concerns
195
+ - **Use Shared Tasks**: Leverage our shared task definitions
196
+ - **Follow Naming**: Use consistent naming conventions
197
+ - **Document Tasks**: Always include descriptions
198
+
199
+ ### Task Dependencies
200
+
201
+ - Use dependencies to ensure prerequisites are met
202
+ - Keep dependency chains short and clear
203
+ - Use silent mode for cleaner output
204
+
205
+ ### Error Handling
206
+
207
+ - Add proper error messages
208
+ - Use exit codes appropriately
209
+ - Handle edge cases
210
+
211
+ ### Version Management
212
+
213
+ - Pin to specific versions of shared tasks
214
+ - Document breaking changes
215
+ - Use semantic versioning
216
+
217
+ ## Troubleshooting
218
+
219
+ ### Common Issues
220
+
221
+ 1. **Task Not Found**
222
+ - Check task name spelling
223
+ - Verify task file is included
224
+ - Check task dependencies
225
+
226
+ 2. **Permission Issues**
227
+ - Ensure scripts are executable
228
+ - Check file permissions
229
+ - Verify user permissions
230
+
231
+ 3. **Variable Issues**
232
+ - Check variable definitions
233
+ - Verify variable scope
234
+ - Check default values
235
+
236
+ ## Additional Resources
237
+
238
+ - [Go Task Documentation](https://taskfile.dev/)
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@lekman/devops-toolkit-tasks",
3
+ "version": "1.4.0",
4
+ "description": "Shared task definitions for SecNord DevOps Toolkit",
5
+ "files": [
6
+ "**/*.yml",
7
+ "templates/**/*.template",
8
+ "README.md"
9
+ ],
10
+ "publishConfig": {
11
+ "registry": "https://registry.npmjs.org/",
12
+ "access": "public"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/lekman/devops-toolkit.git"
17
+ },
18
+ "scripts": {
19
+ "prepublishOnly": "npm run test",
20
+ "test": "exit 0",
21
+ "version": "git add -A tasks",
22
+ "build": "exit 0"
23
+ },
24
+ "keywords": [
25
+ "task",
26
+ "devops",
27
+ "automation"
28
+ ],
29
+ "author": "SecNord",
30
+ "license": "UNLICENSED"
31
+ }