Skip to content

Commit df0448f

Browse files
committed
Added GitHub Actions workflow for Docker image build and updated setup scripts for installation methods
1 parent 28f4fd1 commit df0448f

4 files changed

Lines changed: 251 additions & 58 deletions

File tree

.github/workflows/ghcr.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
docker:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log in to GitHub Container Registry
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract Docker metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
type=ref,event=branch
48+
type=ref,event=tag
49+
type=sha
50+
51+
- name: Build and optionally push Docker image
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
file: ./Dockerfile
56+
push: ${{ github.event_name != 'pull_request' }}
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,23 @@ git clone https://github.com/DebaA17/CVE-scanner-cli.git
2828
cd CVE-scanner-cli
2929
bash setup.sh
3030
```
31-
This will install all dependencies in a virtual environment and create a `cvecli` command in your `~/.local/bin` directory.
31+
The setup script offers two install methods:
32+
33+
- Docker (recommended): pulls the prebuilt GHCR image and adds a `cvecli` alias to your default shell.
34+
- Local machine: creates the virtual environment, installs dependencies, and links `cvecli` into `~/.local/bin`.
35+
36+
You can also choose the install method directly:
37+
38+
```bash
39+
bash setup.sh --docker
40+
```
41+
42+
```bash
43+
bash setup.sh --local
44+
```
45+
46+
If your current terminal was already open before setup, reload it with:
3247

33-
The setup script also adds `~/.local/bin` to your shell startup file if it is missing. If your current terminal was already open before setup, reload it with:
3448
```bash
3549
source ~/.bashrc
3650
```
@@ -42,13 +56,13 @@ source ~/.zshrc
4256
```
4357

4458
## Uninstall
45-
To remove the global `cvecli` command and the PATH entry added by setup, run:
59+
To remove the global `cvecli` command, Docker alias, and any PATH entry added by setup, run:
4660

4761
```bash
4862
bash uninstall.sh
4963
```
5064

51-
This removes the `~/.local/bin/cvecli` launcher and cleans the PATH line from your shell startup files. It does not delete the repository folder or `myenv`.
65+
This removes the `~/.local/bin/cvecli` launcher, removes the Docker alias from your shell startup files, and cleans the PATH line if it was added for the local install. It does not delete the repository folder or `myenv`.
5266

5367
## Docker Setup
5468
Build and run the CLI with Docker in one line:
@@ -57,6 +71,14 @@ Build and run the CLI with Docker in one line:
5771
docker build -t cvecli . && docker run --rm -it cvecli
5872
```
5973

74+
Use the prebuilt image from GitHub Container Registry:
75+
76+
```bash
77+
docker run --rm -it ghcr.io/debaa17/cve-scanner-cli:latest
78+
```
79+
80+
The GitHub Actions workflow publishes `latest` on pushes to `main` and publishes version tags when you create releases like `v1.0.0`.
81+
6082
Run a direct CVE lookup without entering interactive mode:
6183

6284
```bash

setup.sh

Lines changed: 144 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,160 @@
22
# Setup script for CVE Scanner CLI (Linux only)
33
set -e
44

5-
# Check for python3
6-
if ! command -v python3 >/dev/null 2>&1; then
7-
echo "Python3 is required but not found. Please install Python3."
8-
exit 1
9-
fi
5+
DOCKER_IMAGE="ghcr.io/debaa17/cve-scanner-cli:latest"
6+
DOCKER_ALIAS="alias cvecli='docker run --rm -it ${DOCKER_IMAGE}'"
7+
PATH_EXPORT='export PATH="$HOME/.local/bin:$PATH"'
8+
INSTALL_METHOD=""
109

11-
# Create virtual environment if not exists
12-
if [ ! -d "myenv" ]; then
13-
python3 -m venv myenv
14-
fi
15-
source myenv/bin/activate
10+
resolve_rc_file() {
11+
local shell_name
1612

17-
# Upgrade pip and install requirements
18-
pip install --upgrade pip
19-
pip install -r requirements.txt
13+
shell_name="$(basename "${SHELL:-}")"
2014

21-
# Make CLI script executable
22-
chmod +x cve_search_cli.py
15+
case "$shell_name" in
16+
bash)
17+
if [ -f "$HOME/.bashrc" ]; then
18+
printf '%s\n' "$HOME/.bashrc"
19+
else
20+
printf '%s\n' "$HOME/.profile"
21+
fi
22+
;;
23+
zsh)
24+
printf '%s\n' "$HOME/.zshrc"
25+
;;
26+
*)
27+
printf '%s\n' "$HOME/.profile"
28+
;;
29+
esac
30+
}
2331

24-
# Optionally create a symlink in ~/.local/bin
25-
mkdir -p "$HOME/.local/bin"
26-
ln -sf "$PWD/cve_search_cli.py" "$HOME/.local/bin/cvecli"
32+
ensure_line_in_file() {
33+
local file_path="$1"
34+
local line="$2"
2735

28-
PATH_EXPORT='export PATH="$HOME/.local/bin:$PATH"'
29-
SHELL_NAME="$(basename "${SHELL:-}")"
30-
RC_FILE=""
36+
touch "$file_path"
37+
if ! grep -Fqx "$line" "$file_path"; then
38+
printf '\n%s\n' "$line" >> "$file_path"
39+
fi
40+
}
41+
42+
remove_line_from_file() {
43+
local file_path="$1"
44+
local line="$2"
45+
local temp_file
46+
47+
if [ ! -f "$file_path" ]; then
48+
return
49+
fi
50+
51+
if ! grep -Fqx "$line" "$file_path"; then
52+
return
53+
fi
54+
55+
temp_file="$(mktemp)"
56+
grep -Fvx "$line" "$file_path" > "$temp_file" || true
57+
mv "$temp_file" "$file_path"
58+
}
59+
60+
print_reload_hint() {
61+
local rc_file="$1"
62+
63+
printf "\033[0;33mOpen a new terminal or run: source %s\033[0m\n" "$rc_file"
64+
}
65+
66+
install_docker() {
67+
local rc_file
68+
69+
if ! command -v docker >/dev/null 2>&1; then
70+
printf "Docker is required for the recommended install method but was not found.\n"
71+
exit 1
72+
fi
73+
74+
rc_file="$(resolve_rc_file)"
75+
docker pull "$DOCKER_IMAGE"
76+
ensure_line_in_file "$rc_file" "$DOCKER_ALIAS"
77+
78+
printf "\033[0;32mDocker install complete. Added cvecli alias to %s\033[0m\n" "$rc_file"
79+
printf "\033[0;32mExample: cvecli --id CVE-2025-55184\033[0m\n"
80+
print_reload_hint "$rc_file"
81+
}
82+
83+
install_local() {
84+
local rc_file
85+
86+
if ! command -v python3 >/dev/null 2>&1; then
87+
printf "Python3 is required but not found. Please install Python3.\n"
88+
exit 1
89+
fi
3190

32-
case "$SHELL_NAME" in
33-
bash)
34-
if [ -f "$HOME/.bashrc" ]; then
35-
RC_FILE="$HOME/.bashrc"
91+
rc_file="$(resolve_rc_file)"
92+
93+
if [ ! -d "myenv" ]; then
94+
python3 -m venv myenv
95+
fi
96+
source myenv/bin/activate
97+
98+
pip install --upgrade pip
99+
pip install -r requirements.txt
100+
101+
chmod +x cve_search_cli.py
102+
mkdir -p "$HOME/.local/bin"
103+
ln -sf "$PWD/cve_search_cli.py" "$HOME/.local/bin/cvecli"
104+
105+
ensure_line_in_file "$rc_file" "$PATH_EXPORT"
106+
remove_line_from_file "$rc_file" "$DOCKER_ALIAS"
107+
108+
printf "\033[0;32mLocal install complete. Use 'cvecli' from anywhere to run the tool.\033[0m\n"
109+
printf "\033[0;32mExample: cvecli --id CVE-2025-55184\033[0m\n"
110+
print_reload_hint "$rc_file"
111+
}
112+
113+
choose_install_method() {
114+
printf "Choose installation method:\n"
115+
printf "1) Docker (recommended)\n"
116+
printf "2) Local machine\n"
117+
printf "Enter choice [1/2]: "
118+
read -r choice
119+
120+
case "$choice" in
121+
1|"")
122+
INSTALL_METHOD="docker"
123+
;;
124+
2)
125+
INSTALL_METHOD="local"
126+
;;
127+
*)
128+
printf "Invalid choice. Use 1 for Docker or 2 for local machine.\n"
129+
exit 1
130+
;;
131+
esac
132+
}
133+
134+
case "${1:-}" in
135+
--docker)
136+
INSTALL_METHOD="docker"
137+
;;
138+
--local)
139+
INSTALL_METHOD="local"
140+
;;
141+
"")
142+
if [ -t 0 ]; then
143+
choose_install_method
36144
else
37-
RC_FILE="$HOME/.profile"
145+
INSTALL_METHOD="docker"
38146
fi
39147
;;
40-
zsh)
41-
RC_FILE="$HOME/.zshrc"
42-
;;
43148
*)
44-
if [ -f "$HOME/.profile" ]; then
45-
RC_FILE="$HOME/.profile"
46-
fi
149+
printf "Usage: bash setup.sh [--docker|--local]\n"
150+
exit 1
47151
;;
48152
esac
49153

50-
if [ -n "$RC_FILE" ]; then
51-
touch "$RC_FILE"
52-
if ! grep -Fqx "$PATH_EXPORT" "$RC_FILE"; then
53-
printf '\n%s\n' "$PATH_EXPORT" >> "$RC_FILE"
54-
printf "\033[0;32mAdded ~/.local/bin to PATH in %s\033[0m\n" "$RC_FILE"
55-
printf "\033[0;33mOpen a new terminal or run: source %s\033[0m\n" "$RC_FILE"
56-
fi
57-
fi
58-
59-
# Print green success message
60-
printf "\033[0;32mSetup complete! Use 'cvecli' from anywhere to run the tool.\033[0m\n"
61-
printf "\033[0;32mExample: cvecli --id CVE-2025-55184\033[0m\n"
154+
case "$INSTALL_METHOD" in
155+
docker)
156+
install_docker
157+
;;
158+
local)
159+
install_local
160+
;;
161+
esac

uninstall.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ set -e
33

44
CLI_LINK="$HOME/.local/bin/cvecli"
55
PATH_EXPORT='export PATH="$HOME/.local/bin:$PATH"'
6+
DOCKER_ALIAS="alias cvecli='docker run --rm -it ghcr.io/debaa17/cve-scanner-cli:latest'"
67
REMOVED_PATH_LINE=0
8+
REMOVED_ALIAS_LINE=0
79

8-
remove_path_line() {
10+
remove_line_from_file() {
911
local rc_file="$1"
12+
local line="$2"
1013
local temp_file
1114

1215
if [ ! -f "$rc_file" ]; then
1316
return
1417
fi
1518

16-
if ! grep -Fqx "$PATH_EXPORT" "$rc_file"; then
19+
if ! grep -Fqx "$line" "$rc_file"; then
1720
return
1821
fi
1922

2023
temp_file="$(mktemp)"
21-
grep -Fvx "$PATH_EXPORT" "$rc_file" > "$temp_file" || true
24+
grep -Fvx "$line" "$rc_file" > "$temp_file" || true
2225
mv "$temp_file" "$rc_file"
23-
REMOVED_PATH_LINE=1
24-
printf "\033[0;32mRemoved PATH entry from %s\033[0m\n" "$rc_file"
2526
}
2627

2728
if [ -L "$CLI_LINK" ] || [ -f "$CLI_LINK" ]; then
@@ -31,12 +32,22 @@ else
3132
printf "\033[0;33mNo cvecli launcher found at %s\033[0m\n" "$CLI_LINK"
3233
fi
3334

34-
remove_path_line "$HOME/.bashrc"
35-
remove_path_line "$HOME/.zshrc"
36-
remove_path_line "$HOME/.profile"
35+
for rc_file in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
36+
if [ -f "$rc_file" ] && grep -Fqx "$PATH_EXPORT" "$rc_file"; then
37+
remove_line_from_file "$rc_file" "$PATH_EXPORT"
38+
REMOVED_PATH_LINE=1
39+
printf "\033[0;32mRemoved PATH entry from %s\033[0m\n" "$rc_file"
40+
fi
41+
42+
if [ -f "$rc_file" ] && grep -Fqx "$DOCKER_ALIAS" "$rc_file"; then
43+
remove_line_from_file "$rc_file" "$DOCKER_ALIAS"
44+
REMOVED_ALIAS_LINE=1
45+
printf "\033[0;32mRemoved Docker alias from %s\033[0m\n" "$rc_file"
46+
fi
47+
done
3748

3849
printf "\033[0;32mUninstall complete.\033[0m\n"
3950

40-
if [ "$REMOVED_PATH_LINE" -eq 1 ]; then
41-
printf "\033[0;33mOpen a new terminal or reload your shell config to apply the PATH change.\033[0m\n"
51+
if [ "$REMOVED_PATH_LINE" -eq 1 ] || [ "$REMOVED_ALIAS_LINE" -eq 1 ]; then
52+
printf "\033[0;33mOpen a new terminal or reload your shell config to apply the shell changes.\033[0m\n"
4253
fi

0 commit comments

Comments
 (0)