Skip to content

Commit

Permalink
Merge pull request #28 from crane-cloud/ft-add-actions
Browse files Browse the repository at this point in the history
feat: add git actions
  • Loading branch information
rhodinemma authored May 17, 2024
2 parents 98f78cc + 6797de3 commit 43a0be9
Show file tree
Hide file tree
Showing 14 changed files with 876 additions and 99 deletions.
File renamed without changes.
32 changes: 32 additions & 0 deletions .github/workflows/bin/create_envs.sh
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
116 changes: 116 additions & 0 deletions .github/workflows/production.yml
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
126 changes: 126 additions & 0 deletions .github/workflows/staging.yml
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
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
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 $?
22 changes: 22 additions & 0 deletions docker/prod/DockerFile
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"]
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"@testing-library/user-event": "^12.1.10",
"axios": "^0.23.0",
"dompurify": "^2.3.3",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.8",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/GoPlay/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import NewHeader from "../NewHeader";
import styles from "./GoPlay.module.css";
import { REGISTER_URL, GOPLAYGROUND_URL } from "../../config";
import { FRONTEND_URL, GOPLAYGROUND_URL } from "../../config";
import { ReactComponent as GoPlayground } from "../../assets/images/go.svg";

function GoPlay() {
Expand All @@ -22,7 +22,7 @@ function GoPlay() {
<p>Simplified environment for learning Go.</p>
<p>Experimentation on loose with Sandbox environment</p>
<p>
<a className={styles.Link} href={`${REGISTER_URL}`}>
<a className={styles.Link} href={`${FRONTEND_URL}/register`}>
Sign up{" "}
</a>{" "}
or if you have an account click below.
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { withRouter } from "react-router-dom";
import Logo from "../Logo";

import styles from "./Header.module.css";
import { DOCS_URL, LOGIN_URL } from "../../config";
import { DOCS_URL, FRONTEND_URL } from "../../config";

const Header = (props) => {
return (
Expand All @@ -21,7 +21,7 @@ const Header = (props) => {
Docs
</a>
<a
href={`${LOGIN_URL}`}
href={`${FRONTEND_URL}/login`}
className={`${styles.HeaderLinkLogin} ${styles.TurnLight}`}
rel="noopener noreferrer"
target="_blank"
Expand Down
Loading

0 comments on commit 43a0be9

Please sign in to comment.