diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..72490fee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +node_modules +build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..db755936 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# create-react-app build environment +FROM node:16-alpine as react-build +WORKDIR /app +ENV PATH /app/node_modules/.bin:$PATH +COPY package*.json ./ +RUN yarn +COPY . ./ +RUN yarn sass +RUN yarn build + +# nginx server environment +FROM nginx:stable-alpine +COPY nginx.conf /etc/nginx/conf.d/configfile.template +ENV PORT 80 +ENV HOST 0.0.0.0 +RUN sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf" +COPY --from=react-build /app/build /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/builder/cloudbuild-dev.yaml b/builder/cloudbuild-dev.yaml new file mode 100644 index 00000000..58f2e05a --- /dev/null +++ b/builder/cloudbuild-dev.yaml @@ -0,0 +1,40 @@ +steps: +#Build the image +- name: 'gcr.io/cloud-builders/docker' + env: + - 'DISABLE_ESLINT_PLUGIN=true' + - 'REACT_APP_ES_PROXY_HOST=$_REACT_APP_ES_PROXY_HOST' + - 'REACT_APP_ES_PROXY_HOST_DEV=$_REACT_APP_ES_PROXY_HOST_DEV' + - 'REACT_APP_API_SERVICE_ADDRESS=$_REACT_APP_API_SERVICE_ADDRESS' + - 'REACT_APP_API_SERVICE_ADDRESS_DEV=$_REACT_APP_API_SERVICE_ADDRESS_DEV' + - 'REACT_APP_API_SERVICE_KEY=$_REACT_APP_API_SERVICE_KEY' + - 'REACT_APP_API_SERVICE_KEY_DEV=$_REACT_APP_API_SERVICE_KEY_DEV' + - 'REACT_APP_SIGNED_URL_ENDPOINT=$_REACT_APP_SIGNED_URL_ENDPOINT' + - 'REACT_APP_USER_REGISTRATION_ENDPOINT=$_REACT_APP_USER_REGISTRATION_ENDPOINT' + - 'REACT_APP_SEND_EMAIL_ENDPOINT=$_REACT_APP_SEND_EMAIL_ENDPOINT' + - 'REACT_APP_FILE_DOWNLOAD_ENDPOINT=$_REACT_APP_FILE_DOWNLOAD_ENDPOINT' + - 'REACT_APP_QC_DATA_ENDPOINT=$_REACT_APP_QC_DATA_ENDPOINT' + - 'REACT_APP_ES_ENDPOINT=$_REACT_APP_ES_ENDPOINT' + - 'REACT_APP_FILE_SEARCH_ENDPOINT=$_REACT_APP_FILE_SEARCH_ENDPOINT' + - 'REACT_APP_DATA_FILE_BUCKET=$_REACT_APP_DATA_FILE_BUCKET' + - 'REACT_APP_QC_REPORT_BUCKET=$_REACT_APP_QC_REPORT_BUCKET' + - 'REACT_APP_QC_REPORT_BUCKET_DEV=$_REACT_APP_QC_REPORT_BUCKET_DEV' + - 'REACT_APP_ES_ACCESS_TOKEN=$_REACT_APP_ES_ACCESS_TOKEN' + - 'REACT_APP_ES_ACCESS_TOKEN_DEV=$_REACT_APP_ES_ACCESS_TOKEN_DEV' + - 'REACT_APP_reCAPTCHA_SITE_KEY=$_REACT_APP_RECAPTCHA_SITE_KEY' + - 'REACT_APP_AUTH0_CLIENT_ID=$_REACT_APP_AUTH0_CLIENT_ID' + script: 'echo $DISABLE_ESLINT_PLUGIN && echo $REACT_APP_ES_PROXY_HOST && echo $REACT_APP_ES_PROXY_HOST_DEV && echo $REACT_APP_API_SERVICE_ADDRESS && echo $REACT_APP_API_SERVICE_ADDRESS_DEV && echo $REACT_APP_API_SERVICE_KEY && echo $REACT_APP_API_SERVICE_KEY_DEV && echo $REACT_APP_SIGNED_URL_ENDPOINT && echo $REACT_APP_USER_REGISTRATION_ENDPOINT && echo $REACT_APP_SEND_EMAIL_ENDPOINT && echo $REACT_APP_FILE_DOWNLOAD_ENDPOINT && echo $REACT_APP_QC_DATA_ENDPOINT && echo $REACT_APP_ES_ENDPOINT && echo $REACT_APP_FILE_SEARCH_ENDPOINT && echo $REACT_APP_DATA_FILE_BUCKET && echo $REACT_APP_QC_REPORT_BUCKET && echo $REACT_APP_QC_REPORT_BUCKET_DEV && echo $REACT_APP_ES_ACCESS_TOKEN && echo $REACT_APP_ES_ACCESS_TOKEN_DEV && echo $REACT_APP_reCAPTCHA_SITE_KEY && echo $REACT_APP_AUTH0_CLIENT_ID' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/motrpac-frontend-dev:$SHORT_SHA', '.'] + +#Push the image +- name: 'gcr.io/cloud-builders/docker' + args: ['push', 'gcr.io/$PROJECT_ID/motrpac-frontend-dev:$SHORT_SHA'] + +# deploy container image to GKE +- name: "gcr.io/cloud-builders/gke-deploy" + args: + - run + - --filename=kubernetes/dev/ + - --image=gcr.io/$PROJECT_ID/motrpac-frontend-dev:$SHORT_SHA + - --location=us-west1-a + - --cluster=motrpac-frontend-dev-cluster diff --git a/builder/cloudbuild-prod.yaml b/builder/cloudbuild-prod.yaml new file mode 100644 index 00000000..d2c15550 --- /dev/null +++ b/builder/cloudbuild-prod.yaml @@ -0,0 +1,17 @@ +steps: +#Build the image +- name: 'gcr.io/cloud-builders/docker' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/motrpac-frontend-prod:$TAG_NAME', '.'] + +#Push the image +- name: 'gcr.io/cloud-builders/docker' + args: ['push', 'gcr.io/$PROJECT_ID/motrpac-frontend-prod:$TAG_NAME'] + +# deploy container image to GKE +- name: "gcr.io/cloud-builders/gke-deploy" + args: + - run + - --filename=kubernetes/prod/ + - --image=gcr.io/$PROJECT_ID/motrpac-frontend-prod:$TAG_NAME + - --location=us-west1-a + - --cluster=motrpac-frontend-prod-cluster diff --git a/builder/cloudbuild-staging.yaml b/builder/cloudbuild-staging.yaml new file mode 100644 index 00000000..0075d818 --- /dev/null +++ b/builder/cloudbuild-staging.yaml @@ -0,0 +1,17 @@ +steps: +#Build the image +- name: 'gcr.io/cloud-builders/docker' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/motrpac-frontend-staging:$SHORT_SHA', '.'] + +#Push the image +- name: 'gcr.io/cloud-builders/docker' + args: ['push', 'gcr.io/$PROJECT_ID/motrpac-frontend-staging:$SHORT_SHA'] + +# deploy container image to GKE +- name: "gcr.io/cloud-builders/gke-deploy" + args: + - run + - --filename=kubernetes/staging/ + - --image=gcr.io/$PROJECT_ID/motrpac-frontend-staging:$SHORT_SHA + - --location=us-west1-a + - --cluster=motrpac-frontend-staging-cluster diff --git a/kubernetes/dev/deployment.yaml b/kubernetes/dev/deployment.yaml new file mode 100644 index 00000000..1a1f0402 --- /dev/null +++ b/kubernetes/dev/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: motrpac-frontend-dev + namespace: motrpac-portal-dev + labels: + app: motrpac-frontend +spec: + replicas: 1 + selector: + matchLabels: + app: motrpac-frontend + env: dev + template: + metadata: + labels: + app: motrpac-frontend + env: dev + spec: + containers: + - name: motrpac-frontend-app + image: gcr.io/motrpac-portal-dev/motrpac-frontend-dev:v1 + ports: + - containerPort: 80 diff --git a/kubernetes/dev/namespace.yaml b/kubernetes/dev/namespace.yaml new file mode 100644 index 00000000..f2aab14c --- /dev/null +++ b/kubernetes/dev/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: "v1" +kind: "Namespace" +metadata: + name: "motrpac-portal-dev" diff --git a/kubernetes/dev/service.yaml b/kubernetes/dev/service.yaml new file mode 100644 index 00000000..2cf5f6c0 --- /dev/null +++ b/kubernetes/dev/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: motrpac-frontend-dev +spec: + type: LoadBalancer + selector: + app: motrpac-frontend + ports: + - port: 80 + targetPort: 80 diff --git a/kubernetes/prod/deployment.yaml b/kubernetes/prod/deployment.yaml new file mode 100644 index 00000000..611b4f9c --- /dev/null +++ b/kubernetes/prod/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: motrpac-frontend-prod + namespace: motrpac-portal-prod + labels: + app: motrpac-frontend +spec: + replicas: 2 + selector: + matchLabels: + app: motrpac-frontend + env: production + template: + metadata: + labels: + app: motrpac-frontend + env: production + spec: + containers: + - name: motrpac-frontend-app + image: gcr.io/motrpac-portal-dev/motrpac-frontend-prod:v1 + ports: + - containerPort: 80 diff --git a/kubernetes/prod/service.yaml b/kubernetes/prod/service.yaml new file mode 100644 index 00000000..92ee75d1 --- /dev/null +++ b/kubernetes/prod/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: motrpac-frontend-prod +spec: + type: LoadBalancer + selector: + app: motrpac-frontend + ports: + - port: 80 + targetPort: 80 diff --git a/kubernetes/staging/deployment.yaml b/kubernetes/staging/deployment.yaml new file mode 100644 index 00000000..09d04f07 --- /dev/null +++ b/kubernetes/staging/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: motrpac-frontend-staging + namespace: motrpac-portal-staging + labels: + app: motrpac-frontend +spec: + replicas: 1 + selector: + matchLabels: + app: motrpac-frontend + env: staging + template: + metadata: + labels: + app: motrpac-frontend + env: staging + spec: + containers: + - name: motrpac-frontend-app + image: gcr.io/motrpac-portal-dev/motrpac-frontend-staging:v1 + ports: + - containerPort: 80 diff --git a/kubernetes/staging/service.yaml b/kubernetes/staging/service.yaml new file mode 100644 index 00000000..ca283bfe --- /dev/null +++ b/kubernetes/staging/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: motrpac-frontend-staging +spec: + type: LoadBalancer + selector: + app: motrpac-frontend + ports: + - port: 80 + targetPort: 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..af609f05 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,18 @@ +server { + listen $PORT; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + gzip on; + gzip_vary on; + gzip_min_length 10240; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; + gzip_disable "MSIE [1-6]\."; + +} diff --git a/package.json b/package.json index f932a581..af765faf 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "DISABLE_ESLINT_PLUGIN='true' react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", "storybook": "start-storybook -p 9009 -s public",