fix: ci.yml #12
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 | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
defaults: | |
run: | |
working-directory: server | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
.github | |
server | |
- name: Decode LINODE_KUBECONFIG | |
env: | |
LINODE_KUBECONFIG: ${{ secrets.LINODE_KUBECONFIG_BASE64 }} | |
run: | | |
echo "${LINODE_KUBECONFIG}" | base64 --decode > decoded_kubeconfig | |
echo "KUBECONFIG_CONTENTS=$(cat decoded_kubeconfig)" >> $GITHUB_ENV | |
- uses: azure/k8s-set-context@v4 | |
with: | |
kubeconfig: ${{ env.KUBECONFIG_CONTENTS }} | |
- name: Build the Docker Image | |
run: docker build -f Dockerfile.prod -t spaces-server:${{ github.sha }} --build-arg FIREBASE_SERVICE_ACCOUNT_KEY_BASE64="${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY_BASE64}}" . | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Tag the Docker Image | |
run: docker tag spaces-server:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:${{ github.sha }} | |
- name: Push the Docker Image | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPO }}:${{ github.sha }} | |
- 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_USERNAME/${{ secrets.DOCKERHUB_USERNAME }}/g" \ | |
-e "s/DOCKERHUB_REPOSITORY/${{ secrets.DOCKERHUB_REPO }}/g" \ | |
-e "s/DOCKERHUB_TAG/${{ github.sha }}/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 |