Skip to content

feat: deploy image to linode cluster #3

feat: deploy image to linode cluster

feat: deploy image to linode cluster #3

Workflow file for this run

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 kubeconfig
run: |
echo "${{ secrets.LINODE_KUBECONFIG_BASE64 }}" | base64 -d > $HOME/kubeconfig.yaml
echo "KUBECONFIG_PATH=$HOME/kubeconfig.yaml" >> $GITHUB_ENV
- uses: azure/k8s-set-context@v4
with:
kubeconfig: ${{ env.KUBECONFIG_PATH }}
- 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: Create DOCKER_CONFIG environment variable
run: echo "DOCKER_CONFIG=$(cat ~/.docker/config.json | base64 -w 0)" >> $GITHUB_ENV
- 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 spaces namespace
run: kubectl apply -f k8s/spaces_ns.yml
- name: Set spaces as the current namespace
run: kubectl config set-context --current --namespace=spaces
- name: Create Dockerhub secret
run: |
sed -i'' -e "s/DOCKERHUB_SECRET/${{ env.DOCKER_CONFIG }}/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
- name: Apply Service
run: kubectl apply -f k8s/spaces-prod_svc.yml