DevOps application from scratch
TGBot is a Telegram bot written in the Go programming language, utilizing the Cobra-CLI v1.8.0 framework for command handling and Telebot v3.1.4 for integration with the Telegram API.
To get started with KBot, clone the repository:
git clone https://github.com/albiorixUA/devops-k8s-demo.git
cd devops-k8s-demoTo install all necessary dependencies and compile the project, use:
go get
go build -ldflags "-X="github.com/albiorixUA/devops-k8s-demo/cmd.appVersion=v1.0.2To test the compiled project, do the following:
./tgbot versionas a result, you should get the app's version v1.0.2.
Enter your Telegram bot token in silent mode:
read -s TELE_TOKENExport the value of the TELE TOKEN variable to the current shell environment.
export TELE_TOKENRun KBot using the following command:
./tgbot startThis project uses a Makefile for common tasks. Run the following commands:
- Format Code:
make format - Lint Code:
make lint - Run Tests:
make test - Get Dependencies:
make get - Build Application:
make build(OverrideREGISTRY,TARGETOSandTARGETARCHwithmake build REGISTRY=albiorixua TARGETOS=windows TARGETARCH=amd64) - Create Docker Image:
make image(OverrideREGISTRY,TARGETOSandTARGETARCHwithmake image REGISTRY=albiorixua TARGETOS=windows TARGETARCH=amd64) - Push Docker Image:
make push(OverrideREGISTRY,TARGETOSandTARGETARCHwithmake push REGISTRY=albiorixua TARGETOS=windows TARGETARCH=amd64) - Clean:
make clean
-
Adding the pre-commit hook:
-
Move the
pre-commitfile to the.git/hooks/folder:cp pre-commit .git/hooks/
-
Alternatively, create a symbolic link::
ln -s pre-commit .git/hooks/pre-commit
-
Ensure that the file has execute permissions:
chmod +x pre-commit
-
-
Activating GitLeaks:
-
Run the command to activate GitLeaks:
git config hooks.gitleaks.enable true
-
-
Commit attempt:
-
Now, with each commit attempt, your pre-commit script will check the code for the presence of sensitive information.
-
If secrets are detected, the commit will be rejected, and you will receive an error message.
-