fix: maybe this should work #25
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: CICD | |
on: | |
push: | |
branches: | |
- '*' | |
env: | |
SERVICE: gore | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
REGION: us-central1 | |
jobs: | |
cicd: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
# - name: Check if PR was merged | |
# run: | | |
# if [ "${{ github.event.pull_request.merged }}" == "true" ]; then | |
# echo "PR was merged." | |
# else | |
# echo "PR was closed without merging." | |
# exit 0 | |
# fi | |
- name: Make envfile | |
uses: SpicyPizza/create-envfile@v2.0 | |
with: | |
file_name: .env | |
envkey_INSTANCE_CONNECTION_NAME: ${{ secrets.INSTANCE_CONNECTION_NAME }} | |
envkey_DB_USER: ${{ secrets.DB_USER }} | |
envkey_DB_NAME: ${{ secrets.DB_NAME }} | |
envkey_DB_PASS: ${{ secrets.DB_PASS }} | |
envkey_GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} | |
envkey_BUCKET_NAME: ${{ secrets.BUCKET_NAME }} | |
envkey_LOCAL_LOG: "FALSE" | |
envkey_CLOUD_LOG: "TRUE" # only cloud logging is needed for the deployed app | |
envkey_LOG_NAME: ${{ secrets.LOG_NAME }} | |
envkey_PROJECT_ID: ${{ env.PROJECT_ID }} | |
envkey_YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }} | |
envkey_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
envkey_API_AUTH_TOKEN: ${{ secrets.API_AUTH_TOKEN }} | |
- name: Create credentials json file | |
uses: jsdaniell/create-json@v1.2.2 | |
with: | |
name: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} | |
json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }} | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v0 | |
with: | |
project_id: ${{ env.PROJECT_ID }} | |
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }} | |
export_default_credentials: true | |
- name: Build Docker image | |
run: docker build -t gore . | |
- name: Tag Docker image for Docker Hub | |
run: docker tag gore ${{ secrets.DOCKER_USERNAME }}/gore:latest | |
# it is a private image on docker hub, hosted there just for my own reference | |
- name: Push Docker image to Docker Hub | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} && docker push ${{ secrets.DOCKER_USERNAME }}/gore:latest | |
- name: Tag Docker image for GCR | |
run: docker tag gore gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:latest | |
- name: Push Docker image to Google Container Registry (GCR) | |
run: | | |
gcloud auth configure-docker | |
docker push gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:latest | |
- name: Deploy to GKE | |
run: | | |
gcloud container clusters get-credentials ${{ env.SERVICE }} --zone ${{ env.REGION }} --project ${{ env.PROJECT_ID }} | |
export USE_GKE_GCLOUD_AUTH_PLUGIN=True | |
gcloud container clusters get-credentials ${{ env.SERVICE }} --zone ${{ env.REGION }} --project ${{ env.PROJECT_ID }} | |
export DEPLOYMENT_NAME=${{ env.SERVICE }}-deployment | |
export SERVICE_NAME=${{ env.SERVICE }}-service | |
kubectl set image deployment/${DEPLOYMENT_NAME} ${DEPLOYMENT_NAME}=gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:latest | |
kubectl rollout status deployment/${DEPLOYMENT_NAME} | |
kubectl get services ${SERVICE_NAME} |