-
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.
Merge pull request #28 from crane-cloud/ft-add-actions
feat: add git actions
- Loading branch information
Showing
14 changed files
with
876 additions
and
99 deletions.
There are no files selected for viewing
File renamed without changes.
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,32 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# env variables | ||
REACT_APP_API_BASE_URL="${REACT_APP_API_BASE_URL}" | ||
REACT_APP_MIRA_API_URL="${REACT_APP_MIRA_API_URL}" | ||
REACT_APP_FRONTEND_URL="${REACT_APP_FRONTEND_URL}" | ||
REACT_APP_DOCS_URL="${REACT_APP_DOCS_URL}" | ||
REACT_APP_BLOG_URL="${REACT_APP_BLOG_URL}" | ||
REACT_APP_CRANE_CLOUD_STATUS="${REACT_APP_CRANE_CLOUD_STATUS}" | ||
REACT_APP_MIRA_DOCS_URL="${REACT_APP_MIRA_DOCS_URL}" | ||
|
||
|
||
function create_env_file | ||
{ | ||
echo REACT_APP_API_BASE_URL=$REACT_APP_API_BASE_URL >> .env | ||
echo REACT_APP_MIRA_API_URL=$REACT_APP_MIRA_API_URL >> .env | ||
echo REACT_APP_FRONTEND_URL=$REACT_APP_FRONTEND_URL >> .env | ||
echo REACT_APP_DOCS_URL=$REACT_APP_DOCS_URL >> .env | ||
echo REACT_APP_BLOG_URL=$REACT_APP_BLOG_URL >> .env | ||
echo REACT_APP_CRANE_CLOUD_STATUS=$REACT_APP_CRANE_CLOUD_STATUS >> .env | ||
echo REACT_APP_MIRA_DOCS_URL=$REACT_APP_MIRA_DOCS_URL >> .env | ||
} | ||
|
||
|
||
function run | ||
{ | ||
create_env_file | ||
} | ||
|
||
run |
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,116 @@ | ||
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: 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 |
---|---|---|
@@ -0,0 +1,126 @@ | ||
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_FRONTEND_URL: ${{ secrets.STAGING_REACT_APP_FRONTEND_URL }} | ||
# REACT_APP_DOCS_URL: ${{ secrets.STAGING_REACT_APP_DOCS_URL }} | ||
# REACT_APP_BLOG_URL: ${{ secrets.STAGING_REACT_APP_BLOG_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 }} | ||
# TODO: revert to the above 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: 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test_and_report: | ||
runs-on: ubuntu-latest | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Install Yarn | ||
run: npm install -g yarn | ||
|
||
- name: Setup Dependencies | ||
run: yarn | ||
|
||
# - name: Setup Code Climate test-reporter | ||
# run: | | ||
# curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter | ||
# chmod +x ./cc-test-reporter | ||
# ./cc-test-reporter before-build | ||
|
||
- name: Run Tests | ||
run: yarn test --detectOpenHandles | ||
|
||
# - name: Code Climate report | ||
# run: ./cc-test-reporter after-build --coverage-input-type lcov --exit-code $? |
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,22 @@ | ||
FROM node:16-alpine as build_step | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json yarn.lock ./ | ||
|
||
RUN yarn install --ignore-engines | ||
|
||
COPY . /app | ||
|
||
RUN yarn build | ||
|
||
|
||
FROM node:16-alpine | ||
|
||
WORKDIR /app | ||
|
||
RUN npm install -g serve | ||
|
||
COPY --from=build_step /app/build . | ||
|
||
CMD ["serve", "-s", "-l", "3000"] |
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
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
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
Oops, something went wrong.