feat: use modules in terraform config #19
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: CI | |
# TODO: only run when server or .github directory contents change | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'server/**' | |
- '.github/**' | |
pull_request: | |
branches: | |
- main | |
paths: | |
- 'server/**' | |
- '.github/**' | |
jobs: | |
build-and-push: | |
env: | |
IMAGE: "${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:${{ github.sha }}" | |
defaults: | |
run: | |
working-directory: server | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
.github | |
server | |
- uses: azure/k8s-set-context@v4 | |
with: | |
kubeconfig: ${{ secrets.LINODE_KUBECONFIG }} # must be the kubeconfig itself, not the path to it | |
- name: Build the Docker Image | |
run: docker build -f Dockerfile.prod -t ${{ env.IMAGE }} --build-arg FIREBASE_SERVICE_ACCOUNT_KEY_BASE64="${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY_BASE64}}" . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push the Docker Image | |
run: docker push ${{ env.IMAGE }} | |
- name: Create namespace | |
run: kubectl apply -f k8s/spaces_ns.yml | |
- name: Set new current namespace | |
run: kubectl config set-context --current --namespace=spaces | |
- name: Create Dockerhub secret | |
run: | | |
sed -i'' \ | |
-e "s/DOCKERHUB_SECRET/$(cat ~/.docker/config.json | base64 -w 0)/g" \ | |
k8s/spaces-dockerhub_secret.yml | |
kubectl apply -f k8s/spaces-dockerhub_secret.yml | |
- name: Apply Deployment | |
run: | | |
sed -i'' \ | |
-e "s|DOCKERHUB_IMAGE|${{ env.IMAGE }}|g" \ | |
k8s/spaces-prod_deploy.yml | |
kubectl apply -f k8s/spaces-prod_deploy.yml | |
- name: Apply Service | |
run: kubectl apply -f k8s/spaces-prod_svc.yml |