Skip to content

Commit b5060e2

Browse files
added argocd cronworkflow integration
1 parent cfa41c7 commit b5060e2

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

argo-cron.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: CronWorkflow
3+
metadata:
4+
name: scsctl-cronworkflow
5+
spec:
6+
schedule: "* * * * *"
7+
concurrencyPolicy: "Replace"
8+
startingDeadlineSeconds: 0
9+
workflowSpec:
10+
entrypoint: scsctl-server-test
11+
templates:
12+
- name: scsctl-server-test
13+
container:
14+
image: ghcr.io/jegathintelops/scsctl:latest
15+

manifest.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Create a manifest for scsctl with a command to run the container
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: scsctl-server
6+
labels:
7+
app: scsctl-server
8+
spec:
9+
containers:
10+
- name: scsctl-server
11+
image: ghcr.io/jegathintelops/scsctl:latest
12+
imagePullPolicy: Always
13+
args: ["server"]
14+
ports:
15+
- containerPort: 5000
16+
restartPolicy: Never
17+
18+
# Create a service to expose the scsctl container
19+
---
20+
apiVersion: v1
21+
kind: Service
22+
metadata:
23+
name: scsctl-loadbalancer
24+
spec:
25+
selector:
26+
app: scsctl-server
27+
ports:
28+
- protocol: TCP
29+
port: 5000
30+
targetPort: 5000
31+
type: LoadBalancer

src/scsctl/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
save_pyroscope_data,
1414
compare_and_find_pyroscope_extra_packages,
1515
)
16-
from scsctl.helper.common import AppDetails, generate_final_report, modify_and_build_docker_image, custom_style_fancy
16+
from scsctl.helper.common import AppDetails, generate_final_report, modify_and_build_docker_image,modify_and_build_docker_images, custom_style_fancy
1717
from scsctl.helper.trivy import get_sbom_report, print_sbom_report, save_sbom_data
1818
from scsctl.helper.renovate import (check_if_node_and_npm_is_installed,check_if_renovate_is_installed_globally,run_renovate_on_a_repository)
1919

@@ -54,7 +54,7 @@ def cli():
5454
@click.option("--renovate_repo_name", help="Repo name for renovate", default=None, is_flag=False, flag_value=None)
5555
@click.option("--non_interactive", help="Run scsctl in non interactive mode", default= False, is_flag=True, flag_value=True)
5656
@click.option(
57-
"--docker_file_folder_path", help="Path of the docker file to rebuild", default=None, is_flag=False, flag_value=None
57+
"--docker_file_folder_path", help="Path of the docker file to rebuild", default=None, is_flag=False, flag_value=None, multiple=True
5858
)
5959
@click.option("--config_file", help="Path of the configuration file", default=None, is_flag=False, flag_value=None)
6060

@@ -220,7 +220,8 @@ def scan(
220220
if choice == "Rebuild the image":
221221
if docker_file_folder_path == None:
222222
docker_file_folder_path = click.prompt("Enter docker file folder path", type=str)
223-
modify_and_build_docker_image(docker_file_folder_path, pyroscope_found_extra_packages, batch_id)
223+
# modify_and_build_docker_image(docker_file_folder_path, pyroscope_found_extra_packages, batch_id)
224+
modify_and_build_docker_images(file_paths=docker_file_folder_path,package_names=pyroscope_found_extra_packages,batch_id=batch_id)
224225

225226

226227
cli.add_command(scan)

src/scsctl/helper/common.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ class AppDetails:
3535
pyroscope_app_name: str
3636
pyroscope_url: str
3737

38+
def modify_and_build_docker_images(file_paths: list, package_names: list, batch_id: str):
39+
counter = 0
40+
for file_path in file_paths:
41+
if os.path.exists("./temp"):
42+
shutil.rmtree("./temp/")
43+
#create folder
44+
os.makedirs("./temp")
45+
shutil.copyfile(file_path, "./temp/Dockerfile")
46+
47+
# Create a new file which contains all the packages names to uninstall
48+
with open("./temp/packages.txt", "w") as f:
49+
f.write("\n".join(package_names))
50+
# Add the uninstall commands at the end of the file
51+
with open("./temp/Dockerfile", "a") as f:
52+
f.write("\nCOPY packages.txt /tmp/packages.txt")
53+
f.write(
54+
'\nRUN while read -r package; do \\\n if dpkg-query -W --showformat=\'${Essential}\' "$package" | grep -q \'^no$\'; then \\\n apt-get remove -y "$package"; \\\n else \\\n echo "Skipping essential package: $package"; \\\n fi; \\\ndone < /tmp/packages.txt'
55+
)
56+
57+
# Build the docker image with the modified Dockerfile and tag it with the batch id
58+
click.echo("Building the docker image...")
59+
try:
60+
subprocess.check_output(["docker", "build", "-t", f"{batch_id}_{counter}", "./temp/"])
61+
except subprocess.CalledProcessError as e:
62+
click.echo(f"Error building the docker image: {e}")
63+
return False
64+
65+
# Remove the temp folder
66+
if os.path.exists("./temp"):
67+
shutil.rmtree("./temp/")
68+
counter += 1
3869

3970
def modify_and_build_docker_image(folder_path: str, package_nammes: list, bacth_id: str):
4071
# Make a copy of folder in a ./temp folder, create folder if it doesn't exist

0 commit comments

Comments
 (0)