Skip to content

Commit

Permalink
remvoe GKE deployments add cloud run for deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
JuribaDev committed Aug 30, 2024
1 parent 6fc6eb5 commit 7aed2ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 105 deletions.
121 changes: 30 additions & 91 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,94 +65,33 @@ jobs:
- name: Install kubectl
run: gcloud components install kubectl

- name: Deploy to GKE
run: |
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} --zone ${{env.LOCATION}} --project ${{ secrets.GCP_PROJECT_ID }}
# Create Namespace if Not Exists
if ! kubectl get namespace ${{ secrets.ENVIRONMENT_NAMESPACE }} &> /dev/null; then
echo "Namespace does not exist. Creating it."
kubectl create namespace ${{ secrets.ENVIRONMENT_NAMESPACE }}
else
echo "Namespace already exists."
fi
# Set correct permissions on manifests
sudo chmod 777 k8s/manifests.yaml
# Update Kubernetes manifests with secrets and environment variables
sed -i "s|ENVIRONMENT_NAMESPACE|${{ secrets.ENVIRONMENT_NAMESPACE }}|g" k8s/manifests.yaml
sed -i "s|MONGODB_URI_SECRET|${{ secrets.MONGODB_URI_SECRET }}|g" k8s/manifests.yaml
sed -i "s|JWT_KEY_SECRET|${{ secrets.JWT_KEY_SECRET }}|g" k8s/manifests.yaml
sed -i "s|LOCATION|${{env.LOCATION}}|g" k8s/manifests.yaml
sed -i "s|PROJECT_ID|${{ secrets.GCP_PROJECT_ID }}|g" k8s/manifests.yaml
sed -i "s|REPO_NAME|${{ secrets.REPO_NAME }}|g" k8s/manifests.yaml
sed -i "s|TAG|${{ github.sha }}|g" k8s/manifests.yaml
sed -i "s|STATIC_IP_NAME_PLACEHOLDER|${{ secrets.STATIC_IP_NAME_PLACEHOLDER }}|g" k8s/manifests.yaml
# Apply Kubernetes manifests
kubectl apply -f k8s/manifests.yaml
- name: Setup TLS and Wait for Deployments
run: |
# Install cert-manager if not already installed
if ! kubectl get namespace cert-manager &> /dev/null; then
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.0/cert-manager.yaml
echo "Waiting for cert-manager to be ready..."
kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=cert-manager -n cert-manager --timeout=300s
else
echo "cert-manager is already installed."
fi
# Wait for cert-manager webhook to be ready
echo "Waiting for cert-manager webhook to be ready..."
kubectl wait --for=condition=ready pod -l app.kubernetes.io/component=webhook -n cert-manager --timeout=300s
sudo chmod 777 k8s/cluster-issuer.yaml
# Create ClusterIssuer if it doesn't exist
if ! kubectl get clusterissuer letsencrypt-prod &> /dev/null; then
sed -i "s|LETSENCRYPT_EMAIL_PLACEHOLDER|${{ secrets.LETSENCRYPT_EMAIL }}|g" k8s/cluster-issuer.yaml
kubectl apply -f k8s/cluster-issuer.yaml
echo "ClusterIssuer created."
else
echo "ClusterIssuer already exists."
# Wait for deployments to be ready
echo "Waiting for server deployment to be ready..."
kubectl rollout status deployment/server-deployment --timeout=300s
echo "Waiting for client deployment to be ready..."
kubectl rollout status deployment/client-deployment --timeout=300s
- name: Wait for TLS Certificate
run: |
echo "Waiting for TLS certificate to be issued..."
max_attempts=20
attempt=0
while [ $attempt -lt $max_attempts ]; do
status=$(kubectl get certificate rnd-platform-tls -o jsonpath="{.status.conditions[?(@.type=='Ready')].status}" 2>/dev/null)
if [ "$status" = "True" ]; then
echo "TLS certificate issued successfully!"
break
elif [ "$status" = "False" ]; then
reason=$(kubectl get certificate rnd-platform-tls -o jsonpath="{.status.conditions[?(@.type=='Ready')].reason}")
echo "Certificate is not ready. Reason: $reason"
else
echo "Certificate status unknown. It may still be processing."
fi
attempt=$((attempt+1))
if [ $attempt -eq $max_attempts ]; then
echo "Maximum attempts reached. Certificate may not be ready."
exit 1
fi
echo "Waiting before next check..."
sleep 30
done
- name: Output Access URL
run: |
echo "Application is accessible at https://rndplatform.juriba.info"
# Deploy server to Cloud Run with environment variables
- name: Deploy Server to Cloud Run
id: deploy-server
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ secrets.SERVER_SERVICE }}
region: ${{env.LOCATION}}
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/${{ secrets.SERVER_SERVICE }}:${{ github.sha }}
env_vars: |
JWT_SECRET=${{ secrets.JWT_KEY_SECRET }}
MONGODB_URI=${{ secrets.MONGODB_URI_SECRET }}
TOKEN_EXPIRATION=${{ secrets.JWT_EXPIRATION }}
# Deploy client to Cloud Run with the server's URL as an environment variable
- name: Deploy Client to Cloud Run
id: deploy-client
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ secrets.CLIENT_SERVICE }}
region: ${{env.LOCATION}}
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/${{ secrets.CLIENT_SERVICE }}:${{ github.sha }}
env_vars: |
SERVER_URL=${{ steps.deploy-server.outputs.url }}
# If required, use the Cloud Run URL outputs in later steps
- name: Show Client URL
run: echo ${{ steps.deploy-client.outputs.url }}

- name: Show Server URL
run: echo ${{ steps.deploy-server.outputs.url }}
14 changes: 0 additions & 14 deletions k8s/cluster-issuer.yaml

This file was deleted.

0 comments on commit 7aed2ab

Please sign in to comment.