Skip to content

Commit

Permalink
fix(ci): change dockerfile with nginx and update env
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Apr 25, 2024
1 parent 4b0ee7d commit 48524f0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: |
IMAGE_ID=ghcr.io/dataesr/ticket-office
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
docker build -t $IMAGE_ID:staging . --file Dockerfile --build-arg VITE_SCANR_API_AUTHORIZATION=${{ secrets.VITE_SCANR_API_AUTHORIZATION }}
docker build -t $IMAGE_ID:staging . --build-arg VITE_SCANR_API_AUTHORIZATION=${{ secrets.VITE_SCANR_API_AUTHORIZATION }}
- name: 📦 Push Docker image
run: |
Expand Down
22 changes: 4 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
FROM node:18-alpine

WORKDIR /app

COPY package*.json .

RUN npm install

COPY . .

ARG VITE_SCANR_API_AUTHORIZATION

ENV VITE_SCANR_API_AUTHORIZATION=VITE_SCANR_API_AUTHORIZATION

RUN npm run build

FROM nginx:stable
COPY dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/templates/nginx.conf.template
ENV API_KEY VITE_SCANR_API_AUTHORIZATION
EXPOSE 5173

CMD [ "npm", "run", "preview" ]

15 changes: 15 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 5173;
resolver 8.8.8.8;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location ~ ^/api/(.*)$ {
proxy_set_header Authorization 'Basic $API_KEY';
proxy_set_header Accept application/json;
proxy_set_header Content-Type application/json;
client_max_body_size 10M;
}
}
24 changes: 17 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"sib-api-v3-sdk": "^8.5.0"
},
"devDependencies": {
"@types/node": "^20.12.7",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@typescript-eslint/eslint-plugin": "^6.10.0",
Expand All @@ -35,4 +36,4 @@
"typescript": "^5.2.2",
"vite": "^5.0.4"
}
}
}
14 changes: 5 additions & 9 deletions src/api/contribution-api/useGetObjectContributeData.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { useState, useEffect } from "react";
import { postHeaders } from "../../config/api";

function useGetContributionData(URL: {}, reload: unknown) {
function useGetContributionData(URL: unknown, reload: unknown) {
const [data, setData] = useState({});
const [isLoading, setLoading] = useState(true);
const [isError, setError] = useState(false);

const { VITE_SCANR_API_AUTHORIZATION } = import.meta.env;
useEffect(() => {
async function getData() {
const url = URL;
const url = URL as RequestInfo;
try {
const response = await fetch(url as RequestInfo, {
headers: {
Authorization: VITE_SCANR_API_AUTHORIZATION,
"Content-Type": "application/json",
},
const response = await fetch(url, {
headers: postHeaders,
});
const res = await response.json();
setData(res);
Expand Down
1 change: 0 additions & 1 deletion src/api/utils/buildURL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const buildURL = (
: "contact";
const sorted = sort === "ASC" ? "sort=created_at" : "sort=-created_at";
const where: any = {};
console.log("test");
if (query.trim() !== "") {
where.$or = [{ name: { $regex: `.*${query}.*`, $options: "i" } }];
if (searchInMessages) {
Expand Down
3 changes: 3 additions & 0 deletions src/config/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { VITE_SCANR_API_AUTHORIZATION: API_KEY } = import.meta.env;
export const headers = API_KEY ? { Authorization: `Basic ${API_KEY}` } : {};
export const postHeaders = { ...headers, "Content-Type": "application/json" };
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
11 changes: 4 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"types": ["vite/client"],
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"declaration": true,
"esModuleInterop": true,
"declarationMap": true,
/* Linting */
"strict": true,
"strict": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
Expand Down

0 comments on commit 48524f0

Please sign in to comment.