add env at bundle #13
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: Staging deployment | |
on: | |
push: | |
branches: | |
- develop | |
- ft-add-actions | |
jobs: | |
build_and_deploy_staging: | |
outputs: | |
image: ${{ steps.export.outputs.image }} | |
tag: ${{ steps.export.outputs.tag }} | |
runs-on: ubuntu-latest | |
env: | |
USE_GKE_GCLOUD_AUTH_PLUGIN: true | |
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} | |
cluster: staging-cluster | |
REACT_APP_API_BASE_URL: https://staging-api.cranecloud.io | |
namespace: cranecloud | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install (Buildx) | |
uses: docker/setup-buildx-action@v1 | |
- name: Set up Docker Buildx | |
run: | | |
docker buildx create --use | |
docker buildx version # Print information to verify that Buildx is set up | |
if: runner.os == 'Linux' # Only run on Linux runners | |
- name: Install kubectl | |
run: | | |
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl | |
chmod +x ./kubectl | |
sudo mv ./kubectl /usr/local/bin/kubectl | |
- name: Login (GCP) | |
uses: google-github-actions/auth@v0 | |
with: | |
credentials_json: ${{ secrets.GCLOUD_SERVICE_KEY }} | |
- name: Get Kubernetes credentials | |
run: | | |
gcloud container clusters get-credentials $cluster --zone us-central1-a | |
- name: Install (Gcloud) | |
uses: google-github-actions/setup-gcloud@v1 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
install_components: "gke-gcloud-auth-plugin" | |
- name: Login (GCP) | |
run: gcloud auth configure-docker | |
- id: meta | |
name: Tag | |
uses: docker/metadata-action@v3 | |
with: | |
flavor: | | |
latest=true | |
images: gcr.io/${{ secrets.GCP_PROJECT_ID }}/cranecloud-cms-frontend | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=sha | |
- name: Add Env vars | |
env: | |
REACT_APP_API_BASE_URL: ${{ secrets.STAGING_REACT_APP_API_BASE_URL }} | |
REACT_APP_MIRA_API_URL: ${{ secrets.STAGING_REACT_APP_MIRA_API_URL }} | |
REACT_APP_REGISTER_URL: ${{ secrets.STAGING_REACT_APP_REGISTER_URL }} | |
REACT_APP_DOCS_URL: ${{ secrets.STAGING_REACT_APP_DOCS_URL }} | |
REACT_APP_BLOG_URL: ${{ secrets.STAGING_REACT_APP_BLOG_URL }} | |
REACT_APP_LOGIN_URL: ${{ secrets.STAGING_REACT_APP_LOGIN_URL }} | |
REACT_APP_CRANE_CLOUD_STATUS: ${{ secrets.STAGING_REACT_APP_CRANE_CLOUD_STATUS }} | |
REACT_APP_MIRA_DOCS_URL: ${{ secrets.STAGING_REACT_APP_MIRA_DOCS_URL }} | |
REACT_APP_MIRA_BLOG_URL: 'https://staging-blog.mira.cranecloud.io' | |
run: | | |
chmod +x ./.github/workflows/bin/create_envs.sh | |
./.github/workflows/bin/create_envs.sh | |
- name: Build | |
uses: docker/build-push-action@v2 | |
with: | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: . | |
file: docker/prod/DockerFile | |
labels: ${{ steps.meta.outputs.labels }} | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
- id: export | |
name: Export | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const metadata = JSON.parse(`${{ steps.meta.outputs.json }}`) | |
const fullUrl = metadata.tags.find((t) => t.includes(':sha-')) | |
if (fullUrl == null) { | |
core.error('Unable to find sha tag of image') | |
} else { | |
const tag = fullUrl.split(':')[1] | |
core.setOutput('image', fullUrl) | |
core.setOutput('tag', tag) | |
} | |
# - name: Create deployment | |
# run: | | |
# kubectl create deployment cranecloud-cms-frontend --image=gcr.io/${{ secrets.GCP_PROJECT_ID }}/cranecloud-cms-frontend:${{ steps.export.outputs.tag }} -n $namespace --replicas=2 | |
# - name: Expose deployment | |
# run: | | |
# kubectl create service nodeport cranecloud-cms-frontend-service --tcp=3000:3000 -n $namespace | |
# - name: Update deployment image | |
# run: | | |
# kubectl set image \ | |
# deployment/cranecloud-cms-frontend \ | |
# cranecloud-cms-frontend=gcr.io/${{ secrets.GCP_PROJECT_ID }}/cranecloud-cms-frontend:${{ steps.export.outputs.tag }} \ | |
# -n $namespace | |
- name: Update deployment | |
run: | | |
kubectl set image deployment/cranecloud-cms-frontend cranecloud-cms-frontend=gcr.io/${{ secrets.GCP_PROJECT_ID }}/cranecloud-cms-frontend:${{ steps.export.outputs.tag }} -n $namespace | |