Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/asignar-volun…
Browse files Browse the repository at this point in the history
…tario
  • Loading branch information
Pinx0 committed Nov 6, 2024
2 parents da3d93d + 1663341 commit 7554cb4
Show file tree
Hide file tree
Showing 22 changed files with 388 additions and 4,711 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/deploy-webapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy webapp

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
- name: Configure kubectl
run: |
echo "${{ secrets.KUBECONFIG }}" > kubeconfig.yml
echo "KUBECONFIG=$PWD/kubeconfig.yml" >> $GITHUB_ENV
- name: Replace variables in Kubernetes manifests
run: |
sed -i "s|VAR_GITHUB_COMMIT_HASH|${{ github.sha }}|g" ./kubernetes.yml
sed -i "s|VAR_GITHUB_TOKEN|${{ secrets.GH_TOKEN }}|g" ./kubernetes.yml
sed -i "s|VAR_SUPABASE_URL|${{ secrets.SUPABASE_URL }}|g" ./kubernetes.yml
sed -i "s|VAR_SUPABASE_ANON_KEY|${{ secrets.SUPABASE_ANON_KEY }}|g" ./kubernetes.yml
sed -i "s|VAR_DATADOG_API_KEY|${{ secrets.DATADOG_API_KEY }}|g" ./kubernetes.yml
- name: Delete existing job
run: |
kubectl delete job emergency-cv--webapp--build--job --namespace production || true
- name: Apply Kubernetes manifests
run: |
kubectl apply -f ./kubernetes.yml
22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
FROM node:18-alpine
ARG CACHE_BURST=1

# Add build arguments for Supabase
ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY

# Set environment variables
ENV NODE_ENV="production" \
ENV NODE_ENV="development" \
NEXT_TELEMETRY_DISABLED=1 \
NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL \
NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY

WORKDIR /app

COPY ./package.json ./yarn.lock ./
COPY package*.json ./

RUN yarn --frozen-lockfile --production=false
# Install ALL dependencies
RUN npm install

COPY ./ ./
COPY . .

RUN yarn build
RUN npm run build

# Switch to production after build
ENV NODE_ENV="production"

# Clean up development dependencies
RUN npm prune --production

EXPOSE 3000
CMD ["yarn", "start"]

CMD ["npm", "start"]
12 changes: 0 additions & 12 deletions Makefile

This file was deleted.

111 changes: 110 additions & 1 deletion kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ metadata:
name: emergency-cv--webapp--deployment
namespace: production
spec:
replicas: 6
replicas: 12
selector:
matchLabels:
app: emergency-cv--webapp
template:
metadata:
labels:
app: emergency-cv--webapp
annotations:
ad.datadoghq.com/emergency-cv--webapp.logs: '[{"source": "nextjs", "service": "emergency-cv-webapp", "log_processing_rules": [{"type": "multi_line", "name": "log_start_with_date", "pattern": "\\d{4}-\\d{2}-\\d{2}"}]}]'
spec:
serviceAccountName: datadog-agent
containers:
- name: emergency-cv--webapp
image: "localhost:30500/emergency-cv/webapp:VAR_GITHUB_COMMIT_HASH"
ports:
- containerPort: 3000
env:
- name: NEXT_PUBLIC_SUPABASE_URL
value: 'VAR_SUPABASE_URL'
- name: NEXT_PUBLIC_SUPABASE_ANON_KEY
value: 'VAR_SUPABASE_ANON_KEY'
livenessProbe:
httpGet:
path: /api/health
Expand All @@ -30,6 +38,59 @@ spec:
port: 3000
initialDelaySeconds: 5
periodSeconds: 5
- name: datadog-agent
image: gcr.io/datadoghq/agent:latest
env:
- name: DD_API_KEY
value: "VAR_DATADOG_API_KEY"
- name: DD_SITE
value: "datadoghq.eu"
- name: DD_LOGS_ENABLED
value: "true"
- name: DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL
value: "true"
- name: DD_APM_ENABLED
value: "true"
- name: DD_APM_NON_LOCAL_TRAFFIC
value: "true"
- name: DD_KUBELET_TLS_VERIFY
value: "false"
- name: DD_PROCESS_AGENT_ENABLED
value: "true"
- name: DD_CONTAINER_EXCLUDE
value: "image:gcr.io/datadoghq/agent"
- name: DD_CONTAINER_INCLUDE_METRICS
value: "name:emergency-cv--webapp"
- name: DD_CONTAINER_INCLUDE_LOGS
value: "name:emergency-cv--webapp"
- name: DD_SYSTEM_PROBE_ENABLED
value: "false"
- name: DD_KUBERNETES_KUBELET_HOST
valueFrom:
fieldRef:
fieldPath: status.hostIP
securityContext:
privileged: false
capabilities:
add: [ "SYS_ADMIN" ]
ports:
- containerPort: 8126
name: traceport
protocol: TCP
volumeMounts:
- name: podslogdir
mountPath: /var/log/pods
readOnly: true
- name: containerlogdir
mountPath: /var/lib/docker/containers
readOnly: true
volumes:
- name: podslogdir
hostPath:
path: /var/log/pods
- name: containerlogdir
hostPath:
path: /var/lib/docker/containers
---
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -61,5 +122,53 @@ spec:
- "--destination=idl-apps--container-registry-service:5000/emergency-cv/webapp:VAR_GITHUB_COMMIT_HASH"
- "--insecure"
- "--skip-tls-verify"
- "--build-arg=NEXT_PUBLIC_SUPABASE_URL=VAR_SUPABASE_URL"
- "--build-arg=NEXT_PUBLIC_SUPABASE_ANON_KEY=VAR_SUPABASE_ANON_KEY"
restartPolicy: Never
backoffLimit: 2
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: datadog-agent
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: datadog-agent
rules:
- apiGroups: [ "" ]
resources:
- nodes
- nodes/metrics
- nodes/proxy
- nodes/spec
- nodes/stats
- pods
- services
- endpoints
- events
verbs: [ "get", "list", "watch" ]
- apiGroups: [ "" ]
resources:
- configmaps
resourceNames: [ "datadog-leader-election" ]
verbs: [ "get", "update" ]
- apiGroups: [ "" ]
resources:
- configmaps
verbs: [ "create" ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: datadog-agent
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: datadog-agent
subjects:
- kind: ServiceAccount
name: datadog-agent
namespace: production
42 changes: 30 additions & 12 deletions src/app/casos-activos/mapa/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import { useRouter, useSearchParams } from 'next/navigation';
import { tiposAyudaOptions } from '@/helpers/constants';
import Map from '@/components/map/map';
import ReactDOMServer from 'react-dom/server';
import { useTowns } from '../../../context/TownProvider';
import { useSession } from '../../../context/SessionProvider';
import PickupPoint from '@/components/PickupPoint';
import { useTowns } from '@/context/TownProvider';

const PAIPORTA_LAT_LNG = [-0.41667, 39.42333];
const DEFAULT_ZOOM = 12;

export default function Mapa() {
const towns = useTowns();
const session = useSession();
const searchParams = useSearchParams();
const router = useRouter();

Expand All @@ -34,6 +33,7 @@ export default function Mapa() {
urgencia: searchParams.get('urgencia') || 'todas',
tipoAyuda: searchParams.get('tipoAyuda') || 'todas',
pueblo: searchParams.get('pueblo') || 'todos',
acepta: searchParams.get('acepta') || 'todos',
});

const changeDataFilter = (type, newFilter) => {
Expand All @@ -56,36 +56,53 @@ export default function Mapa() {
};
}

// caso,
// towns,
// isHref,
// button = { text: 'Ver solicitud', link: '/solicitud/' },
// isEdit = false,
function transformPickupRequestToMarker(point) {
return {
urgency: point.urgency || 'baja',
coordinates: [point.longitude ?? 0, point.latitude ?? 0],
width: '600px',
descriptionHTML: ReactDOMServer.renderToString(<PickupPoint point={point} />),
};
}

async function fetchData() {
try {
setLoading(true);
setError(null);

// Comenzamos la consulta
const query = supabase.from('help_requests').select('*').eq('type', 'necesita');

if (filtroData.tipoAyuda !== 'todas') {
query.contains('help_type', [filtroData.tipoAyuda]);
}

if (filtroData.urgencia !== 'todas') {
query.eq('urgency', filtroData.urgencia);
}

const { data, error } = await query.order('created_at', { ascending: false });

const pickupQuery = supabase.from('collection_points').select('*', { count: 'exact' });
if (filtroData.acepta !== 'todos') {
query.contains('accepted_items', [filtroData.acepta]);
}

const { data: pickupData, error: pickupError } = await pickupQuery.order('created_at', { ascending: false });

let allData = [];
if (error) {
console.log('Error fetching solicitudes:', error);
setData([]);
} else {
const markers = data.map(transformHelpRequestToMarker);
setData(markers || []);
allData.push(...(markers || []));
}
if (pickupError) {
console.log('Error fetching pickup points:', pickupError);
} else {
const pickupMarkers = pickupData.map(transformPickupRequestToMarker);
allData.push(...(pickupMarkers || []));
}

setData(allData);
} catch (err) {
console.log('Error general:', err);
setError('Error de conexión.');
Expand Down Expand Up @@ -143,6 +160,7 @@ export default function Mapa() {
</select>
</div>
</div>

<div className="grid gap-4">
<Map markers={data} center={PAIPORTA_LAT_LNG} zoom={DEFAULT_ZOOM} />
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/app/casos-activos/ofertas/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function Ofertas() {
query.contains('help_type', [filtroData.ayuda]);
}

query.neq('status', 'finished');
// Ejecutar la consulta con paginación
const { data, count, error } = await query
.range((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage - 1)
Expand Down Expand Up @@ -140,7 +141,7 @@ export default function Ofertas() {
</button>
</div>
) : (
data.map((caso) => <OfferCard caso={caso} isHref={true} key={caso.id} />)
data.map((caso) => <OfferCard caso={caso} towns={towns} isHref={true} key={caso.id} />)
)}
</div>
<div className="flex items-center justify-center">
Expand Down
Loading

0 comments on commit 7554cb4

Please sign in to comment.