diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index c760be32..6fae0813 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -45,7 +45,7 @@ jobs: ECR_REPOSITORY: web-callisto-ecr-repository IMAGE_TAG: frontend run: | - docker build -f Dockerfile.client --build-arg BUILD_ENV=${{ env.STAGING_BUILD_ENV }} --rm --platform=linux/amd64 -t ${{ env.FRONTEND_NAME }}:${{ env.VERSION }} . + docker build -f Dockerfile.staging.client --build-arg BUILD_ENV=${{ env.STAGING_BUILD_ENV }} --rm --platform=linux/amd64 -t ${{ env.FRONTEND_NAME }}:${{ env.VERSION }} . docker tag ${{ env.FRONTEND_NAME }}:${{ env.VERSION }} $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT @@ -129,7 +129,7 @@ jobs: ECR_REPOSITORY: web-callisto-ecr-repository IMAGE_TAG: frontend run: | - docker build -f Dockerfile.client --build-arg BUILD_ENV=${{ env.PROD_BUILD_ENV }} --rm --platform=linux/amd64 -t ${{ env.FRONTEND_NAME }}:${{ env.VERSION }} . + docker build -f Dockerfile.staging.client --build-arg BUILD_ENV=${{ env.PROD_BUILD_ENV }} --rm --platform=linux/amd64 -t ${{ env.FRONTEND_NAME }}:${{ env.VERSION }} . docker tag ${{ env.FRONTEND_NAME }}:${{ env.VERSION }} $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT diff --git a/Dockerfile.staging.client b/Dockerfile.staging.client new file mode 100644 index 00000000..7d28ce6e --- /dev/null +++ b/Dockerfile.staging.client @@ -0,0 +1,28 @@ +# DESCRIPTION: Dockerfile for surveystream_frontend react app + +# Build step #1: build the React front end +FROM node:16-alpine as build-step +ARG BUILD_ENV + +WORKDIR / +ENV PATH /node_modules/.bin:$PATH + +COPY package.json tailwind.config.js /tsconfig.json ./ +RUN npm install --network-timeout=100000 +RUN npx browserslist@latest --update-db + +# Copying source code later so that we can avoid npm install everytime +COPY src src +COPY public public +COPY .env.${BUILD_ENV} .env.${BUILD_ENV} +RUN npm run build:${BUILD_ENV} + +# Build step #2: build an nginx container +FROM nginx:stable-alpine +COPY --from=build-step /build /usr/share/nginx/html +# Copy the nginx config template +COPY ./nginx.staging.conf.template /etc/nginx/conf.d/default.conf.template +# Install envsubst for variable substitution +RUN apk add --no-cache gettext +# Entrypoint to substitute env vars and start nginx +CMD envsubst '$ALB_BASE_URL' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;' \ No newline at end of file diff --git a/nginx.staging.conf b/nginx.staging.conf new file mode 100644 index 00000000..34781a3c --- /dev/null +++ b/nginx.staging.conf @@ -0,0 +1,36 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + error_page 500 502 503 504 /50x.html; + + gzip on; + gzip_disable "msie6"; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_min_length 256; + gzip_types text/plain application/json text/html text/css text/javascript; + + proxy_connect_timeout 300; + proxy_send_timeout 300; + proxy_read_timeout 300; + client_max_body_size 80m; + + location / { + try_files $uri $uri/ /index.html; + add_header Cache-Control "no-cache"; + } + + location /static { + expires 1y; + add_header Cache-Control "public"; + } + + location /api { + proxy_pass http://${ALB_BASE_URL}; + } +} \ No newline at end of file diff --git a/nginx.staging.conf.template b/nginx.staging.conf.template new file mode 100644 index 00000000..45f3c54e --- /dev/null +++ b/nginx.staging.conf.template @@ -0,0 +1,36 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + error_page 500 502 503 504 /50x.html; + + gzip on; + gzip_disable "msie6"; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_min_length 256; + gzip_types text/plain application/json text/html text/css text/javascript; + + proxy_connect_timeout 300; + proxy_send_timeout 300; + proxy_read_timeout 300; + client_max_body_size 80m; + + location / { + try_files $uri $uri/ /index.html; + add_header Cache-Control "no-cache"; + } + + location /static { + expires 1y; + add_header Cache-Control "public"; + } + + location /api { + proxy_pass http://$ALB_BASE_URL; + } +} \ No newline at end of file diff --git a/src/modules/DQ/DQChecks/DQCheckGroup1.tsx b/src/modules/DQ/DQChecks/DQCheckGroup1.tsx index 4a170f52..41a8bc1f 100644 --- a/src/modules/DQ/DQChecks/DQCheckGroup1.tsx +++ b/src/modules/DQ/DQChecks/DQCheckGroup1.tsx @@ -28,7 +28,6 @@ import { fetchModuleName, getDQChecks, postDQChecks, - postDQChecksBulk, putDQChecks, } from "../../../redux/dqChecks/apiService"; import { getDQConfig } from "../../../redux/dqChecks/dqChecksActions"; @@ -479,41 +478,20 @@ function DQCheckGroup1({ surveyUID, formUID, typeID }: IDQCheckGroup1Props) { }); } else { setLoading(true); - if ( - data.variable_name && - Array.isArray(data.variable_name) && - data.variable_name.length > 1 - ) { - postDQChecksBulk(formUID, typeID, formData).then((res: any) => { - if (res?.data?.success) { - closeAddManualDrawer(); - message.success("DQ checks added successfully", 1, () => { - loadDQChecks(); - setDataLoading(true); - setSelectedVariableRows([]); - setLoading(false); - }); - } else { - message.error("Failed to add DQ Checks"); - setLoading(false); - } - }); - } else { - postDQChecks(formUID, typeID, formData).then((res: any) => { - if (res?.data?.success) { - closeAddManualDrawer(); - message.success("DQ added successfully", 1, () => { - loadDQChecks(); - setDataLoading(true); - setSelectedVariableRows([]); - setLoading(false); - }); - } else { - message.error("Failed to add DQ Check"); + postDQChecks(formUID, typeID, formData).then((res: any) => { + if (res?.data?.success) { + closeAddManualDrawer(); + message.success("DQ added successfully", 1, () => { + loadDQChecks(); + setDataLoading(true); + setSelectedVariableRows([]); setLoading(false); - } - }); - } + }); + } else { + message.error("Failed to add DQ Check"); + setLoading(false); + } + }); } }; diff --git a/src/modules/DQ/DQChecks/DQCheckGroup2.tsx b/src/modules/DQ/DQChecks/DQCheckGroup2.tsx index 09811679..a91a3267 100644 --- a/src/modules/DQ/DQChecks/DQCheckGroup2.tsx +++ b/src/modules/DQ/DQChecks/DQCheckGroup2.tsx @@ -13,7 +13,6 @@ import { fetchModuleName, getDQChecks, postDQChecks, - postDQChecksBulk, putDQChecks, } from "../../../redux/dqChecks/apiService"; import { getDQConfig } from "../../../redux/dqChecks/dqChecksActions"; @@ -387,41 +386,20 @@ function DQCheckGroup2({ surveyUID, formUID, typeID }: IDQCheckGroup1Props) { }); } else { setLoading(true); - if ( - data.variable_name && - Array.isArray(data.variable_name) && - data.variable_name.length > 1 - ) { - postDQChecksBulk(formUID, typeID, formData).then((res: any) => { - if (res?.data?.success) { - closeAddManualDrawer(); - message.success("DQ checks added successfully", 1, () => { - loadDQChecks(); - setDataLoading(true); - setSelectedVariableRows([]); - setLoading(false); - }); - } else { - message.error("Failed to add DQ Checks"); - setLoading(false); - } - }); - } else { - postDQChecks(formUID, typeID, formData).then((res: any) => { - if (res?.data?.success) { - closeAddManualDrawer(); - message.success("DQ added successfully", 1, () => { - loadDQChecks(); - setDataLoading(true); - setSelectedVariableRows([]); - setLoading(false); - }); - } else { - message.error("Failed to add DQ Check"); + postDQChecks(formUID, typeID, formData).then((res: any) => { + if (res?.data?.success) { + closeAddManualDrawer(); + message.success("DQ added successfully", 1, () => { + loadDQChecks(); + setDataLoading(true); + setSelectedVariableRows([]); setLoading(false); - } - }); - } + }); + } else { + message.error("Failed to add DQ Check"); + setLoading(false); + } + }); } }; diff --git a/src/modules/DQ/DQChecks/DQCheckGroup3.tsx b/src/modules/DQ/DQChecks/DQCheckGroup3.tsx index 9c528c4b..2ad04c8a 100644 --- a/src/modules/DQ/DQChecks/DQCheckGroup3.tsx +++ b/src/modules/DQ/DQChecks/DQCheckGroup3.tsx @@ -13,7 +13,6 @@ import { fetchModuleName, getDQChecks, postDQChecks, - postDQChecksBulk, putDQChecks, } from "../../../redux/dqChecks/apiService"; import { getDQConfig } from "../../../redux/dqChecks/dqChecksActions"; @@ -376,41 +375,20 @@ function DQCheckGroup3({ surveyUID, formUID, typeID }: IDQCheckGroup3Props) { }); } else { setLoading(true); - if ( - data.variable_name && - Array.isArray(data.variable_name) && - data.variable_name.length > 1 - ) { - postDQChecksBulk(formUID, typeID, formData).then((res: any) => { - if (res?.data?.success) { - closeAddManualDrawer(); - message.success("DQ checks added successfully", 1, () => { - loadDQChecks(); - setDataLoading(true); - setSelectedVariableRows([]); - setLoading(false); - }); - } else { - message.error("Failed to add DQ Checks"); - setLoading(false); - } - }); - } else { - postDQChecks(formUID, typeID, formData).then((res: any) => { - if (res?.data?.success) { - closeAddManualDrawer(); - message.success("DQ added successfully", 1, () => { - loadDQChecks(); - setDataLoading(true); - setSelectedVariableRows([]); - setLoading(false); - }); - } else { - message.error("Failed to add DQ Check"); + postDQChecks(formUID, typeID, formData).then((res: any) => { + if (res?.data?.success) { + closeAddManualDrawer(); + message.success("DQ added successfully", 1, () => { + loadDQChecks(); + setDataLoading(true); + setSelectedVariableRows([]); setLoading(false); - } - }); - } + }); + } else { + message.error("Failed to add DQ Check"); + setLoading(false); + } + }); } }; diff --git a/src/redux/dqChecks/apiService.ts b/src/redux/dqChecks/apiService.ts index 3e7d4bd6..56705b0c 100644 --- a/src/redux/dqChecks/apiService.ts +++ b/src/redux/dqChecks/apiService.ts @@ -126,33 +126,6 @@ export const postDQChecks = async ( } }; -export const postDQChecksBulk = async ( - form_uid: string, - type_id: string, - formData: any -) => { - try { - await getCSRFToken(); - const csrfToken = await getCookie("CSRF-TOKEN"); - const url = `${API_BASE_URL}/dq/checks_bulk?form_uid=${form_uid}&type_id=${type_id}`; - - const res = await axios.post( - url, - { ...formData }, - { - headers: { - "X-CSRF-Token": csrfToken, - "Content-Type": "application/json", - }, - withCredentials: true, - } - ); - return res; - } catch (error) { - return error; - } -}; - export const putDQChecks = async (dq_check_uid: number, formData: any) => { try { await getCSRFToken(); @@ -250,5 +223,4 @@ export const api = { getDQChecks, postDQChecks, deleteDQChecks, - postDQChecksBulk, };