Skip to content

Commit

Permalink
feat: finish db url setup
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiFilipeCampos committed Sep 2, 2024
1 parent af18e93 commit a01d2cd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/kubectl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,13 @@ jobs:
uses: actions/checkout@v1

-
name: Configure EKS
working-directory: ./k8s
shell: bash
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
DB_URL: postgresql://${{ needs.start-runner.outputs.db_username }}:${{ secrets.db_password }}@${{ needs.start-runner.outputs.db_endpoint }}/postgres
AWS_SECRET_ACCESS_KEY: "op://${{ env.PROJECT_ENV }}/aws_credentials/AWS_SECRET_ACCESS_KEY"
AWS_ACCESS_KEY_ID: "op://${{ env.PROJECT_ENV }}/aws_credentials/AWS_ACCESS_KEY_ID"
run: |
op run -- aws eks update-kubeconfig --region eu-south-1 --name cloud-dev-infra
op run -- kubectl get nodes
op run -- kubectl apply -f manifest.yml
op run -- helm repo add coder-v2 https://helm.coder.com/v2
op run -- helm upgrade --install coder coder-v2/coder \
--namespace coder \
--values values.yml \
--version 2.13.5
run: make kubectl_deploy

stop-runner:
if: ${{ always() }}
Expand Down
2 changes: 1 addition & 1 deletion k8s/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ metadata:
namespace: coder
type: Opaque
stringData:
url: "$(DB_URL)"
url: ""
42 changes: 37 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,40 @@ up:
CONTAINER_ID=$$(devcontainer --workspace-folder . up | tail -n 1 | jq -r '.containerId[0:-1]')
@docker exec -itw $$WORKSPACE_FOLDER $$CONTAINER_ID bash

run_kubectl:
dagger call run-instance --op-token=cmd:"op read op://$$PROJECT_ENV/actions-kubectl/OP_SERVICE_ACCOUNT_TOKEN"
# @act --job kubectl -P ghcr.io/catthehacker/ubuntu:act-22.04 --secret OP_SERVICE_ACCOUNT_TOKEN=$$( op read op://$$PROJECT_ENV/actions-kubectl/OP_SERVICE_ACCOUNT_TOKEN)
#
export CMD=$(dagger call run-instance --op-token=cmd:"op read op://$PROJECT_ENV/actions-kubectl/OP_SERVICE_ACCOUNT_TOKEN")
act_kubectl:
@act --job kubectl -P ghcr.io/catthehacker/ubuntu:act-22.04 --secret OP_SERVICE_ACCOUNT_TOKEN=$$( op read op://$$PROJECT_ENV/actions-kubectl/OP_SERVICE_ACCOUNT_TOKEN)

kubectl_updatesecret:
B64_DB_URL=$$(echo -n $$DB_URL | base64 -w 0)
SECRET_JSON=$$(op run -- kubectl get secret coder-db-url -o json -n coder)
NEW_SECRET_JSON=$$(echo $$SECRET_JSON | jq ".data.url=\"$$B64_DB_URL\"")
echo $$NEW_SECRET_JSON | op run -- kubectl apply -f -

kubectl_restartdeployment:
op run -- kubectl rollout restart deployment coder -n coder

kubectl_getsecret:
op run -- kubectl get secret coder-db-url -o json -n coder

kubectl_setup:
op run -- aws eks update-kubeconfig --region eu-south-1 --name cloud-dev-infra

kubectl_apply:
op run -- kubectl apply -f ./k8s/manifest.yml

helm:
op run -- helm repo add coder-v2 https://helm.coder.com/v2
op run -- helm upgrade --install coder coder-v2/coder \
--namespace coder \
--values ./k8s/values.yml \
--version 2.13.5
kubectl_getpods:
op run -- kubectl get pods -n coder

kubectl_deploy:
make kubectl_setup
make kubectl_apply
make helm
make kubectl_updatesecret
make kubectl_restartdeployment

0 comments on commit a01d2cd

Please sign in to comment.