Skip to content

Commit c138c5a

Browse files
Feat/actions (#127)
1 parent bd27f8d commit c138c5a

File tree

6 files changed

+308
-6
lines changed

6 files changed

+308
-6
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
name: "run remote bash commands without ssh"
3+
on:
4+
workflow_call:
5+
inputs:
6+
command:
7+
required: false
8+
description: "Specify the Bash command to be executed"
9+
type: string
10+
working-directory:
11+
required: false
12+
description: "Specify the location for command execution"
13+
type: string
14+
slack_username:
15+
description: "It is the name displayed to others in Message on Slack channel"
16+
required: false
17+
type: string
18+
slack_footer:
19+
description: "Additional information or context often placed at the bottom of a message in Slack"
20+
required: false
21+
type: string
22+
slack_icon:
23+
description: "The visual representation associated with a user or a group on Slack"
24+
required: false
25+
type: string
26+
slack_message:
27+
description: "The content or information you want to share on Slack, which is a messaging platform."
28+
required: false
29+
type: string
30+
slack_color:
31+
description: "The visual styling applied to elements within a message or interface on Slack."
32+
required: false
33+
type: string
34+
slack-notification:
35+
description: "Sending a brief message to a designated Slack channel."
36+
default: false
37+
type: string
38+
secrets:
39+
AWS_REGION:
40+
required: true
41+
description: "Specify the AWS region where the EC2 instance is located"
42+
AWS_ACCESS_KEY_ID:
43+
required: true
44+
description: "Provide the AWS access key ID for authentication"
45+
AWS_SECRET_ACCESS_KEY:
46+
required: true
47+
description: "Provide the AWS secret access key for authentication"
48+
INSTANCE_ID:
49+
required: true
50+
description: "Specify the AWS EC2 instance ID or IDs"
51+
SLACK_WEBHOOK_URL:
52+
required: false
53+
description: "Specify Slack Incoming Webhook URL"
54+
jobs:
55+
ssm-send-commands:
56+
runs-on: ubuntu-latest
57+
58+
steps:
59+
- uses: actions/checkout@v2
60+
61+
- name: Execute Remote Command via AWS SSM
62+
uses: peterkimzz/aws-ssm-send-command@master
63+
id: ssm
64+
with:
65+
aws-region: ${{ secrets.AWS_REGION }}
66+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
instance-ids: ${{ secrets.INSTANCE_ID }}
69+
working-directory: ${{ inputs.working-directory }}
70+
command: |-
71+
${{ inputs.command }}
72+
73+
- name: Slack notification
74+
if: ${{ inputs.slack-notification == 'true' && always() }}
75+
uses: rtCamp/action-slack-notify@v2
76+
env:
77+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
78+
SLACK_MESSAGE: ${{ inputs.slack_message }}
79+
SLACK_ICON: ${{ inputs.slack_icon }}
80+
SLACK_USERNAME: ${{ inputs.slack_username }}
81+
SLACK_FOOTER: ${{ inputs.slack_footer }}
82+
SLACK_COLOR: ${{ job.status }}
83+
slack-notification: ${{ inputs.slack-notification }}
84+
...
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
name: "remote ssh command"
3+
on:
4+
workflow_call:
5+
inputs:
6+
port:
7+
description: "Specify the SSH port number for the remote connection."
8+
type: string
9+
default: "22"
10+
sync:
11+
description: "Enable synchronous execution when dealing with multiple hosts."
12+
type: string
13+
required: false
14+
timeout:
15+
description: "Timeout duration for establishing an SSH connection to the host."
16+
type: string
17+
default: "30s"
18+
required: false
19+
command_timeout:
20+
description: "Timeout duration for executing SSH commands."
21+
type: string
22+
default: "10m"
23+
required: false
24+
script:
25+
description: "Specify the commands to be executed on the remote host."
26+
required: false
27+
type: string
28+
script_stop:
29+
description: "Stop the script after the first failure."
30+
type: string
31+
default: false
32+
envs:
33+
description: "Specify environment variables to be passed to the remote shell script."
34+
type: string
35+
debug:
36+
description: "Enable debug mode for additional logging."
37+
type: string
38+
default: false
39+
request_pty:
40+
description: "Request a pseudo-terminal from the server."
41+
type: string
42+
default: false
43+
slack_username:
44+
description: "It is the name displayed to others in Message on Slack channel"
45+
required: false
46+
type: string
47+
slack_footer:
48+
description: "Additional information or context often placed at the bottom of a message in Slack"
49+
required: false
50+
type: string
51+
slack_icon:
52+
description: "The visual representation associated with a user or a group on Slack"
53+
required: false
54+
type: string
55+
slack_message:
56+
description: "The content or information you want to share on Slack, which is a messaging platform."
57+
required: false
58+
type: string
59+
slack_color:
60+
description: "The visual styling applied to elements within a message or interface on Slack."
61+
required: false
62+
type: string
63+
slack-notification:
64+
description: "sending a brief message to a designated Slack channel."
65+
default: false
66+
type: string
67+
secrets:
68+
PRIVATE_SSH_KEY:
69+
description: "Private SSH Key for secure communication with the server."
70+
required: true
71+
HOST:
72+
description: "Public IP address of the server for remote access."
73+
required: true
74+
USERNAME:
75+
description: "Username for authentication on the remote system or service."
76+
required: true
77+
SLACK_WEBHOOK_URL:
78+
description: Specify Slack Incoming Webhook URL
79+
required: false
80+
jobs:
81+
ssh-action:
82+
runs-on: ubuntu-latest
83+
84+
steps:
85+
- name: Checkout git repo
86+
uses: actions/checkout@v4
87+
88+
- name: executing remote ssh commands using ssh key
89+
uses: appleboy/[email protected]
90+
with:
91+
host: ${{ secrets.HOST }}
92+
username: ${{ secrets.USERNAME }}
93+
key: ${{ secrets.PRIVATE_SSH_KEY }}
94+
port: ${{ inputs.port }}
95+
envs: ${{ inputs.envs }}
96+
request_pty: ${{ inputs.request_pty }}
97+
script: |
98+
${{ inputs.script }}
99+
100+
- name: slack notification
101+
if: ${{ inputs.slack-notification == 'true' && always() }}
102+
uses: rtCamp/action-slack-notify@v2
103+
env:
104+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
105+
SLACK_MESSAGE: ${{ inputs.slack_message }}
106+
SLACK_ICON: ${{ inputs.slack_icon }}
107+
SLACK_USERNAME: ${{ inputs.slack_username }}
108+
SLACK_FOOTER: ${{ inputs.slack_footer }}
109+
SLACK_COLOR: ${{ job.status }}
110+
slack-notification: ${{ inputs.slack-notification }}
111+
...

.github/workflows/docker-scanner.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ on:
77
severity:
88
required: true
99
type: string
10+
dockerfile-path:
11+
required: false
12+
type: string
13+
default: ./Dockerfile
14+
description: dockerfile path
15+
security-upload:
16+
default: false
17+
type: string
18+
description: "Enable image scan report upload to GitHub Security tab."
1019

1120
jobs:
1221
build-image:
@@ -32,6 +41,7 @@ jobs:
3241
load: true # Export to Docker Engine rather than pushing to a registry
3342
tags: ${{ github.sha }}
3443
platforms: linux/amd64
44+
file: ${{inputs.dockerfile-path}}
3545

3646
- name: Docker Scan with trivy (non-blocking)
3747
uses: aquasecurity/trivy-action@master
@@ -44,6 +54,7 @@ jobs:
4454
output: 'trivy-results.sarif'
4555

4656
- name: Upload Trivy scan results to GitHub Security tab
57+
if: ${{ inputs.security-upload == 'true' }}
4758
uses: github/codeql-action/upload-sarif@v3
4859
with:
4960
sarif_file: 'trivy-results.sarif'

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ Above example is just a simple example to call workflow from github shared workf
6161
* [Example for terraform checks with digitalocean cloud](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/terraform-checks.md#example-for-terraform-checks-with-digitalocean-cloud)
6262
6. [Terraform Lint Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/terraform-lint.md)
6363
7. [Terraform Checks Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/terraform-checks.md)
64-
7. [Checkov Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/checkov.md)
65-
8. [Terraform Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/terraform_workflow.md)
66-
9. [Infracost workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/infracost.md)
67-
10. [ Deploy Cloudformation Stack workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/deploy-cloudformation.md)
68-
11. [ Deploy Cloudformation Stackset workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/deploy-cloudformation-stackset.md)
69-
12. [ Readme Generation workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/readme.md)
64+
8. [Checkov Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/checkov.md)
65+
9. [Terraform Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/terraform_workflow.md)
66+
10. [Infracost workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/infracost.md)
67+
11. [ Deploy Cloudformation Stack workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/deploy-cloudformation.md)
68+
12. [ Deploy Cloudformation Stackset workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/deploy-cloudformation-stackset.md)
69+
13. [ Readme Generation workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/readme.md)
70+
14. [ AWS SSM Send Command workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/AWSSSMSendCommand.md)
71+
15. [ Remote SSH Command workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/docs/RemoteSSHCommand.md)
7072
7173
## Feedback
7274
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/github-shared-workflows/issues), or feel free to drop us an email at [[email protected]](mailto:[email protected]).

docs/AWSSSMSendCommand.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Running the bash commands on ec2 instance without SSH
2+
3+
## Requirements
4+
5+
- To utilize this action, you must configure your IAM user with the AWS IAM Role "AmazonSSMFullAccess".
6+
- EC2 instance needs to be associated with an IAM Role that includes the "AmazonSSMFullAccess" policy.
7+
8+
9+
#### [running bash command without ssh workflow](https://github.com/clouddrove/github-shared-workflows/blob/feat/docker-scanner/.github/workflows/AWSSSMsendCommand.yml)
10+
11+
- This workflow is used to run the bash commands on Ec2 instance without ssh and Send the Notification to the particular slack channel after the completion of github-action using the Slack Webhook url.
12+
13+
#### Usage
14+
15+
- This action helps you to execute remote bash command for AWS EC2 instance without SSH or other accessing. Also send the Notification to Slack channel after the completion of GitHub-action whether its (Pass, fail or cancelled.)
16+
17+
#### Example for running the bash commands on ec2 instance without SSH and send notification to Slack channel.
18+
19+
````yaml
20+
name: Bash commands without ssh
21+
permissions:
22+
contents: read
23+
packages: write
24+
pull-requests: write
25+
26+
on:
27+
workflow_dispatch:
28+
29+
jobs:
30+
bash-commands-without-ssh:
31+
uses: clouddrove/github-shared-workflows/.github/workflows/AWSSSMSendCommand.yml@master
32+
with:
33+
working-directory: # Specify the working directory for the job
34+
slack_message: # Message to be sent to Slack
35+
slack_icon: # Icon for Slack message
36+
slack_username: # Username for Slack message
37+
slack_footer: # Footer for Slack message
38+
slack_color: # Color for Slack message
39+
slack-notification: # Enable or disable Slack notifications (example 'true' or 'false')
40+
command: |-
41+
# Add your bash commands here
42+
43+
secrets:
44+
AWS_REGION: # AWS region for authentication
45+
AWS_ACCESS_KEY_ID: # AWS access key ID for authentication
46+
AWS_SECRET_ACCESS_KEY: # AWS secret access key for authentication
47+
INSTANCE_ID: # ID of the instance for the bash commands
48+
SLACK_WEBHOOK_URL: # Webhook URL for sending messages to Slack
49+
````

docs/RemoteSSHCommand.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Running the bash commands on ec2 instance using private ssh key
2+
3+
#### [running bash command with ssh workflow](https://github.com/clouddrove/github-shared-workflows/blob/feat/docker-scanner/.github/workflows/RemoteSSHCommand.yml)
4+
5+
- This workflow is used to run the bash commands on Ec2 instance using the private ssh key and Send the Notification to the particular slack channel after the completion of github-action using the Slack Webhook url.
6+
7+
#### Usage
8+
9+
- This workflow is designed to run all the bash commands on Ec2 instance using the private ssh key and also send the Notification to Slack channel after the completion of GitHub-action whether its Pass, fail or cancelled.
10+
11+
#### Example for running the bash commands on ec2 instance using private ssh key and send notification to Slack channel.
12+
13+
````yaml
14+
name: Bash-commands with ssh Workflow
15+
permissions:
16+
contents: read
17+
packages: write
18+
pull-requests: write
19+
20+
on:
21+
workflow_dispatch:
22+
23+
jobs:
24+
ssh-commands:
25+
uses: clouddrove/github-shared-workflows/.github/workflows/RemoteSSHCommand.yml@master
26+
with:
27+
port: # your_ssh_port
28+
timeout: # your_timeout_in_seconds
29+
command_timeout: # your_command_timeout_in_seconds
30+
slack_message: # your_slack_notification_message
31+
slack_icon: # your_slack_icon_url
32+
slack_username: # your_slack_username
33+
slack_footer: # your_slack_footer
34+
slack_color: # your_slack_color
35+
slack-notification: # Enable or disable Slack notifications (example 'true' or 'false')
36+
script: |-
37+
# Add your bash commands here
38+
39+
secrets:
40+
HOST: # Hostname or IP address of the EC2 instance
41+
PRIVATE_SSH_KEY: # Private SSH key for authenticating with the EC2 instance
42+
USERNAME: # SSH username for connecting to the EC2 instance
43+
SLACK_WEBHOOK_URL: # Slack Webhook URL for sending notifications
44+
45+
````

0 commit comments

Comments
 (0)