-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
name: Production deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build_and_deploy_to_production: | ||
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://api.cranecloud.io | ||
namespace: cranecloud-prod | ||
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.PROD_REACT_APP_API_BASE_URL }} | ||
REACT_APP_MIRA_API_URL: ${{ secrets.PROD_REACT_APP_MIRA_API_URL }} | ||
REACT_APP_FRONTEND_URL: ${{ secrets.PROD_REACT_APP_FRONTEND_URL }} | ||
REACT_APP_DOCS_URL: ${{ secrets.PROD_REACT_APP_DOCS_URL }} | ||
REACT_APP_BLOG_URL: ${{ secrets.PROD_REACT_APP_BLOG_URL }} | ||
REACT_APP_CRANE_CLOUD_STATUS: ${{ secrets.PROD_REACT_APP_CRANE_CLOUD_STATUS }} | ||
REACT_APP_MIRA_DOCS_URL: ${{ secrets.PROD_REACT_APP_MIRA_DOCS_URL }} | ||
|
||
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 | ||
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 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ on: | |
push: | ||
branches: | ||
- develop | ||
- ft-add-actions | ||
|
||
jobs: | ||
build_and_deploy_staging: | ||
|