-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from JuribaDev/dev
Dev
- Loading branch information
Showing
117 changed files
with
22,120 additions
and
12,379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
LOCAL_MONGODB_URI=mongodb://admin:password@localhost:27017/dev_database?authSource=admin | ||
|
||
JWT_SECRET=your_jwt_secret_key_here | ||
JWT_EXPIRATION=8h | ||
|
||
PORT=3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: Build and Deploy Docker Images | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
|
||
env: | ||
LOCATION: me-central1 | ||
|
||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Authenticate to Google Cloud | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | ||
|
||
- name: Set up Google Cloud SDK | ||
uses: google-github-actions/setup-gcloud@v2 | ||
with: | ||
project_id: ${{ secrets.GCP_PROJECT_ID }} | ||
|
||
- name: Configure Docker for Artifact Registry | ||
run: | | ||
gcloud auth configure-docker ${{env.LOCATION}}-docker.pkg.dev | ||
- name: Build and push Docker image for client | ||
run: | | ||
docker build \ | ||
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | ||
--build-arg GITHUB_SHA=${{ github.sha }} \ | ||
--build-arg GITHUB_REF_NAME=${{ github.ref_name }} \ | ||
-f apps/client/Dockerfile \ | ||
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }}-${{ github.ref_name }} \ | ||
. | ||
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }}-${{ github.ref_name }} | ||
- name: Build and push Docker image for server | ||
run: | | ||
docker build \ | ||
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | ||
--build-arg GITHUB_SHA=${{ github.sha }} \ | ||
--build-arg GITHUB_REF_NAME=${{ github.ref_name }} \ | ||
-f apps/server/Dockerfile \ | ||
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }}-${{ github.ref_name }} \ | ||
. | ||
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }}-${{ github.ref_name }} | ||
- name: Deploy Server to Cloud Run | ||
id: deploy-server | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
service: ${{ secrets.SERVER_SERVICE }} | ||
region: ${{env.LOCATION}} | ||
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }}-${{ github.ref_name }} | ||
env_vars: | | ||
JWT_SECRET=${{ secrets.JWT_KEY_SECRET }} | ||
PROD_MONGODB_URI=${{ secrets.MONGODB_URI_SECRET }} | ||
TOKEN_EXPIRATION=${{ secrets.JWT_EXPIRATION }} | ||
flags: | | ||
--port 3000 | ||
--memory 512Mi | ||
--cpu 1 | ||
--max-instances 3 | ||
--min-instances 1 | ||
--concurrency 80 | ||
--ingress=internal | ||
timeout: 600s | ||
|
||
- name: Deploy Client to Cloud Run | ||
id: deploy-client | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
service: ${{ secrets.CLIENT_SERVICE }} | ||
region: ${{env.LOCATION}} | ||
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }}-${{ github.ref_name }} | ||
env_vars: | | ||
API_URL=${{ steps.deploy-server.outputs.url }} | ||
flags: | | ||
--port 80 | ||
--memory 256Mi | ||
--cpu 1 | ||
--max-instances 3 | ||
--min-instances 1 | ||
--concurrency 100 | ||
--allow-unauthenticated | ||
--ingress=internal-and-cloud-load-balancing | ||
timeout: 600s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
.env | ||
.nx/cache | ||
.nx/workspace-data | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,49 @@ | ||
# Build stage | ||
FROM docker.io/node:lts-alpine3.20 AS build | ||
FROM node:lts-alpine AS build | ||
WORKDIR /app | ||
|
||
RUN apk add --no-cache python3 make g++ | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm ci | ||
|
||
COPY . . | ||
RUN npm run build -- --prod | ||
|
||
# Production stage | ||
RUN npx nx build client --configuration=production | ||
|
||
FROM nginx:stable-alpine | ||
COPY --from=build /app/dist/client /usr/share/nginx/html | ||
COPY nginx.conf /etc/nginx/nginx.conf | ||
RUN chown -R nginx:nginx /usr/share/nginx/html && chmod -R 755 /usr/share/nginx/html && \ | ||
chown -R nginx:nginx /var/cache/nginx && \ | ||
chown -R nginx:nginx /var/log/nginx && \ | ||
chown -R nginx:nginx /etc/nginx/conf.d | ||
|
||
ARG GITHUB_SHA | ||
ARG BUILD_DATE | ||
ARG GITHUB_REF_NAME | ||
LABEL org.opencontainers.image.title="R&D Platform Client" | ||
LABEL org.opencontainers.image.source="https://github.com/JuribaDev/rnd-platform" | ||
LABEL org.opencontainers.image.revision=${GITHUB_SHA} | ||
LABEL org.opencontainers.image.created=${BUILD_DATE} | ||
LABEL org.opencontainers.image.version=${GITHUB_REF_NAME} | ||
LABEL maintainer="Juriba Saleh [email protected]" | ||
|
||
COPY --from=build /app/dist/apps/client/browser /usr/share/nginx/html | ||
|
||
COPY apps/client/nginx.conf /etc/nginx/nginx.conf | ||
|
||
RUN apk add --no-cache gettext | ||
|
||
COPY apps/client/env.sh /docker-entrypoint.d/40-env.sh | ||
|
||
RUN chmod +x /docker-entrypoint.d/40-env.sh | ||
|
||
RUN chown -R nginx:nginx /usr/share/nginx/html && \ | ||
chmod -R 755 /usr/share/nginx/html && \ | ||
chown -R nginx:nginx /var/cache/nginx && \ | ||
chown -R nginx:nginx /var/log/nginx && \ | ||
chown -R nginx:nginx /etc/nginx/conf.d | ||
|
||
RUN touch /var/run/nginx.pid && \ | ||
chown -R nginx:nginx /var/run/nginx.pid | ||
chown -R nginx:nginx /var/run/nginx.pid | ||
|
||
USER nginx | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
log() { | ||
echo "[INFO] $1" | ||
} | ||
|
||
if [ -z "$API_URL" ]; then | ||
echo "[ERROR] API_URL environment variable is not set." | ||
exit 1 | ||
fi | ||
|
||
log "Replacing API_URL in main JavaScript files" | ||
|
||
find /usr/share/nginx/html/ -name 'main*.js' -exec sed -i 's|apiUrl:[^,]*|apiUrl:"'"${API_URL}"'"|g' {} + | ||
|
||
log "API_URL successfully replaced in JavaScript files" | ||
|
||
log "Verifying changes in JavaScript files" | ||
for file in /usr/share/nginx/html/main*.js; do | ||
head -n 5 "$file" | ||
done | ||
|
||
log "Script completed successfully" |
Oops, something went wrong.