terraform reporting lambda #97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: API CI | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- run: echo ${{ secrets.REGISTRY_TOKEN }} | docker login ghcr.io -u USERNAME --password-stdin | |
- run: echo "ENV VERSION=$GITHUB_SHA" >> ./Dockerfile | |
- name: Build the Docker image | |
run: docker build ./api --file ./api/Dockerfile --tag ghcr.io/gessfred/keybored-api:$GITHUB_SHA | |
- run: docker push ghcr.io/gessfred/keybored-api:$GITHUB_SHA | |
- run: docker build ./api --file ./api/Dockerfile --tag ghcr.io/gessfred/keybored-api:latest | |
- run: docker push ghcr.io/gessfred/keybored-api:latest | |
test: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Test SQL queries | |
run: | | |
cd sql | |
pip install -r requirements.txt | |
pytest | |
- name: Test API | |
run: | | |
cd api | |
pip install -r requirements.txt | |
pytest | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install doctl | |
uses: digitalocean/[email protected] | |
with: | |
token: ${{ secrets.DIGITAL_OCEAN_TOKEN }} | |
version: 1.91.0 | |
# - run: sudo snap install doctl | |
# - run: sudo snap connect doctl:kube-config | |
# - run: sudo ls /home/runner/ | |
# - run: sudo mkdir /home/runner/.config/doctl | |
# - run: sudo doctl auth init -t ${{ secrets.DIGITAL_OCEAN_TOKEN }} | |
# - run: sudo apt-get install -y ca-certificates curl | |
# - run: curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg | |
# - run: echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list | |
# - run: sudo apt-get update -y && sudo apt-get install -y kubectl | |
- run: /opt/hostedtoolcache/doctl/1.91.0/x64/doctl version | |
- run: sudo ls /home/runner/.config/doctl/ | |
- run: sudo mkdir /root/.kube | |
#- run: sudo ls -al /root/.kube | |
- run: sudo /opt/hostedtoolcache/doctl/1.91.0/x64/doctl kubernetes cluster kubeconfig save k8s-amiscan-1-22-7-do-0-fra1-1648193990670 | |
- run: sed -i "s/:latest/:${GITHUB_SHA}/g" ./api/deployment.yaml | |
- run: sudo kubectl config get-contexts | |
- run: sudo kubectl config use-context do-fra1-k8s-amiscan-1-22-7-do-0-fra1-1648193990670 | |
- run: sudo kubectl apply -f ./api/deployment.yaml | |
name: Shipping... | |
- name: Install PostgreSQL client | |
run: sudo apt-get -yqq install postgresql-client | |
- name: Create View | |
env: | |
DB_HOST: ${{ secrets.DB_HOST }} | |
DB_NAME: ${{ secrets.DB_NAME }} | |
DB_USER: ${{ secrets.DB_USER }} | |
PGPASSWORD: ${{ secrets.DB_PASSWORD }} | |
run: echo "create or replace view typing_speed_current as $(cat sql/typing_speed_current.sql)" | psql -h $DB_HOST -U $DB_USER -d keylogger -p 25060 |