t.me/dkzippa_bot
- use https://github.com/cosmtrek/air
- change/use
Makefile - use
.envfile withgodotenv
- create repo
github.com/dkzippa/prometheus-kbot go mod init github.com/dkzippa/prometheus-kbotgo getwhen have dependenciesgo install github.com/spf13/cobra-cli@latestcobra-cli initcobra-cli add versioncobra-cli add kbotgo run main.gogo run main.go version- compile
make compileorgo build -x --ldflags="-X 'github.com/dkzippa/prometheus-kbot/cmd.appVersion=v1.0.0'" ./prometheus-kbot version- use
gopkg.infor telebot gofmt -s -w ./go getgo build -x --ldflags="-X 'github.com/dkzippa/prometheus-kbot/cmd.appVersion=v1.0.1'"- create new bot 'kbot' 'dkzippa_kbot' in godfather
read -s TELE_TOKEN- (command+v)
export TELE_TOKEN- go to t.me/dkzippa_bot and test
-
add Makefile
- build app for diff platforms: linux, macos, windows, arm
- add clean, format for the kbot app
- add docker image building
-
add Dockerfile
- use multistage build
- create image from goland and build the app with
make <platform> - create image from scratch and run kbot app in it(copy from dev image)
-
add .dockerignore
-
commit, push git codebase
-
don't forget to add tags
-
push image to registry(dockerhub login)
-
test all on other stages
- change
ENTRYPOINT ["./kbot"]toENTRYPOINT ["./kbot", "prometheusKbot"]to have it running - pass
TELE_TOKENas env - commit, push
- add version tag like
v1.0.5, push tags - test image in docker
docker run -ti dkzippa/prometheus-kbot:v1.0.6-ca17012-amd64docker run -ti -e TELE_TOKEN=... dkzippa/prometheus-kbot:v1.0.6-ca17012-amd64
- test image in deployment
k create deploy kbot-test --image dkzippa/prometheus-kbot:v1.0.6-ca17012-amd64
-
helm create helm
-
change Chart.yaml
nameto app nameprometheus-kbot -
test deploy by helm
helm template prometheus-kbot ./helm -s templates/deployment.yaml | k apply -f - -
commit, push
-
set tag, push tags
git push --tags -
helm package ./helm -
gh release create -
gh release list -
gh release upload v1.0.6 prometheus-kbot-0.0.6.tgz -
helm install prometheus-kbot https://github.com/dkzippa/prometheus-kbot/releases/download/v1.0.6/prometheus-kbot-0.0.6.tgz -
helper commands:
- work with secret:
k create secret generic kbot --from-literal=token=...# converts to base64 automatically- to recheck:
echo -n "..." | base64 - see if it is correct:
k get secrets kbot -o yaml k delete secret/kbot
- check logs of 1st pod:
k get po && POD="pod/$(k get po -o jsonpath='{.items[0].metadata.name}')" && k describe $POD && k logs $POD -f
- delete 1st deploy:
k get deploy && k delete "deployment.apps/$(k get deploy -o jsonpath='{.items[0].metadata.name}')"
- work with secret:
-
test ghcr.io/dkzippa
- create personal token with permissions for packages operations(read, write) and repo(write) to push changes later
CR_PAT=... && echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdinmake image push REGISTRY=ghcr.io/dkzippa APP=prometheus-kbotdocker inspect ghcr.io/dkzippa/prometheus-kbot:v1.0.6-2eea280-arm64docker run -e TELE_TOKEN=... -ti ghcr.io/dkzippa/prometheus-kbot:v1.0.6-2eea280-arm64
-
add github worflows and actions
- test updating version
VERSION=$(git describe --tags --abbrev=0)-$(git rev-parse --short HEAD) && echo $VERSIONexport TEST_VERSION2=$(git describe --tags --abbrev=0)-$(git rev-parse --short HEAD) && echo $TEST_VERSION2 && yq -i '.image.tag=strenv(TEST_VERSION2)' ./helm/values.yaml
- commit and push with tags
MSG="github ci/cd implemented" && git add --all && git commit -m $MSG && git push -u origin develop
- test updating version
MSG="version v1.0.10 fix" && git add --all && git commit -m $MSG && git push -u origin developgit tag v.1.0.10 && git push --tags