# Usage **Table of Contents** * [Usage](#usage) * [just](#just) * [examples](#examples) * [dev](#dev) * [prod](#prod) * [gitleaks](#gitleaks) ## just Build runner to abstract away most of the [Dev](Usage.md#dev) and [Prod](Usage.md#prod) commands. ```bash just --list Available recipes: build # [docker] build locally build-clean # [docker] arm build w/docker-compose defaults (no push due to arm64) buildx # [docker] arm build checkbash # [check] lint sh script default # [halp] list available commands down # [docker] remove docker-compose container(s) and networks env # [heroku] update env vars exec # [docker] ssh into container export-reqs args=CWD # [deps] export requirements.txt install args=CWD # [init] install dependencies, tooling, and virtual environment logs # [heroku] get current heroku logs open # [heroku] open heroku url pre-commit # [git] update pre-commit hooks pull # [heroku] pull latest image push # [heroku] push latest image / kick off a build on heroku from ci release # [docker] release to heroku run # [docker] run container run-heroku # [heroku] run container hosted on heroku sh args=SCRIPT # [scripts] run script in working directory stats # [heroku] get current heroku status stop # [docker] stop docker-compose container sub # [git] update git submodules up # [docker] start docker-compose container update-deps args=CWD # [deps] update dependencies ``` ### examples ```bash just stats just release just open just logs ``` ## dev ```bash # docker docker-compose build --pull --parallel --no-cache docker-compose up -d # poetry poetry install poetry run main.py # curl/httpie/requests (httpie shown) # install httpie brew update brew install httpie # root λ http :3000 HTTP/1.1 200 OK content-length: 25 content-type: application/json date: Thu, 11 Aug 2022 06:22:01 GMT server: uvicorn { "message": "Hello World" } # get events λ http :3000/api/events HTTP/1.1 200 OK ... { "city": { "3": "Oklahoma City", ... }, "date": { "3": "2022-08-12T09:30-05:00", }, "description": { "3": "If you can't make it to the [UXOK](https://uxok.org/) design conf...", }, "eventUrl": { "3": "https://www.meetup.com/okccoffeeandcode/events/287519063", }, "name": { "3": "OKC Coffee and Code", }, "title": { "3": "UXOK Watch Party", } } # exports to cwd/raw/output.json λ http POST :3000/api/export HTTP/1.1 200 OK ... null # post formatted query results to slack λ http POST :3000/api/slack HTTP/1.1 200 OK ... null ``` ## prod * Heroku * Setup ```bash # install brew tap heroku/brew && brew install heroku # autocomplete + login heroku autocomplete --refresh-cache # log into heroku container registry (registry.heroku.com) (cf. `unauthorized: authentication required`) heroku container:login # move to git repo cd meetup-bot-bot/ # set app export HEROKU_APP=meetup-bot-bot # config vars heroku config # stack heroku stack # ubuntu 22.* buildpack # heroku stack:set heroku-22 # set heroku git to app heroku git:remote -a $HEROKU_APP # custom container via manifest heroku stack:set container # programmatically add .env vars to heroku config vars cat .env | tr '\n' ' ' | xargs heroku config:set -a $HEROKU_APP # deploy to heroku git push heroku main # watch logs (build, server activity) heroku logs --tail # test image locally docker pull registry.heroku.com/meetup-bot-bot/web docker run --rm -it registry.heroku.com/meetup-bot-bot/web bash # control remote builds (e.g., CI) heroku plugins:install heroku-builds # get all builds # * NOTE: append `-a $HEROKU_APP` if env var isn't set heroku builds # cancel specific build λ heroku builds:cancel fd8ee600-46d8-4f2c-99e9-b77c109ba431 Stopping build fd8ee600-46d8-4f2c-99e9-b77c109ba431... done # cancel latest build heroku builds:cancel ``` * Container manifest * See `heroku.yml` * Creates a container from `Dockerfile.web`, attaches postgres, logging (coralogix) and a scheduler * Container registry * Faster than CI builds triggered by GitHub commits ```bash # login heroku container:login # heroku wrapper build (w/cache) heroku container:push web # pull buildx image (on remote intel box) docker pull moby/buildkit:buildx-stable-1 # create builder docker buildx create \ --name amd64_builder \ --node linux_amd64_builder \ --platform linux/amd64 \ ssh://USERNAME@IP_ADDRESS_OF_BUILDER # select new builder docker buildx use amd64_builder # docker buildx (arm) export TAG="registry.heroku.com/meetup-bot-bot/web:latest" # build intel image docker buildx build -f Dockerfile.web --progress=plain -t $TAG --load . # push to heroku registry docker push registry.heroku.com/meetup-bot-bot/web # release image to app heroku container:release web # exec/ssh into container heroku ps:exec # open website heroku open ``` * Usage ```bash # deploy container via heroku.yml heroku create meetup-bot-bot --manifest # setup python buildpack heroku buildpacks:add heroku/python # add a web worker heroku ps:scale web=1 # stop dyno via `web=0` # destroy app heroku apps:destroy -a meetup-bot-bot --confirm $HEROKU_APP ``` * TODO: document scheduler.sh w/API commands ## gitleaks * git pre-commit hook ```bash git config hooks.gitleaks true ``` * CI/CD * See `meetup_bot/.github/workflows/main.yml` * Manual run ```bash # set env vars export GITLEAKS_CONFIG=$(pwd)/gitleaks.toml # precedence: --config, env var, --source, default config export GITLEAKS_REPORT=$(pwd)/gitleaks_report.json # bash completion gitleaks completion bash >> ~/.gitleaks.bash echo ". ~/.gitleaks.bash" >> ~/.bashrc # scan local directories for secrets gitleaks detect --no-git # run w/report gitleaks detect -r $GITLEAKS_REPORT # generate json report (default) ```