Skip to content

Commit

Permalink
extract backend url to variable
Browse files Browse the repository at this point in the history
  • Loading branch information
t0lia committed Jul 2, 2024
1 parent cca6724 commit 2ff791e
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 17 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ jobs:
context: ./frontend
file: ./frontend/Dockerfile
push: false
tags: retypeme/retypeme-frontend:latest
tags: retypeme/retypeme-frontend-uat:latest
build-args: |
NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY=${{ secrets.NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY }}
NEXT_PUBLIC_API_DOMAIN: ${{NEXT_PUBLIC_API_DOMAIN_UAT}}
- name: Build Docker frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: false
tags: retypeme/retypeme-frontend-prod:latest
build-args: |
NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY=${{ secrets.NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY }}
NEXT_PUBLIC_API_DOMAIN: ${{NEXT_PUBLIC_API_DOMAIN_PROD}}
14 changes: 13 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ jobs:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: retypeme/retypeme-frontend:${{ env.newTag }}, retypeme/retypeme-frontend:latest
tags: retypeme/retypeme-frontend-uat:${{ env.newTag }}, retypeme/retypeme-frontend-uat:latest
build-args: |
NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY=${{ secrets.NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY }}
NEXT_PUBLIC_API_DOMAIN: ${{NEXT_PUBLIC_API_DOMAIN_UAT}}
- name: Build and push Docker frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: retypeme/retypeme-frontend-prod:${{ env.newTag }}, retypeme/retypeme-frontend-prod:latest
build-args: |
NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY=${{ secrets.NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY }}
NEXT_PUBLIC_API_DOMAIN: ${{NEXT_PUBLIC_API_DOMAIN_PROD}}
2 changes: 1 addition & 1 deletion .jenkins/deploy-prod.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pipeline {
steps {
withCredentials([string(credentialsId: 'JASYPT_ENCRYPTOR_PASSWORD_PROD', variable: 'JASYPT_ENCRYPTOR_PASSWORD')]) {
sh '''
/var/lib/jenkins/.local/bin/ansible-playbook -i /var/lib/jenkins/inventory.yml --extra-vars "version=${VERSION}" deploy/deploy_prod.yml
/var/lib/jenkins/.local/bin/ansible-playbook -i /var/lib/jenkins/inventory.yml --extra-vars "env=prod" --extra-vars "version=${VERSION}" deploy/deploy_prod.yml
'''
}
}
Expand Down
2 changes: 1 addition & 1 deletion .jenkins/deploy-uat.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pipeline {
steps {
withCredentials([string(credentialsId: 'JASYPT_ENCRYPTOR_PASSWORD_UAT', variable: 'JASYPT_ENCRYPTOR_PASSWORD')]) {
sh '''
/var/lib/jenkins/.local/bin/ansible-playbook -i /var/lib/jenkins/inventory.yml --extra-vars "version=${VERSION}" deploy/deploy_uat.yml
/var/lib/jenkins/.local/bin/ansible-playbook -i /var/lib/jenkins/inventory.yml --extra-vars "env=uat" --extra-vars "version=${VERSION}" deploy/deploy_uat.yml
'''
}
}
Expand Down
4 changes: 4 additions & 0 deletions deploy/deploy_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
debug:
var: version

- name: Debug env variable
debug:
var: env

- name: ensure directory retypeme exists
file:
path: /home/wheel/retypeme
Expand Down
4 changes: 4 additions & 0 deletions deploy/deploy_uat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
debug:
var: version

- name: Debug env variable
debug:
var: env

- name: ensure directory retypeme exists
file:
path: /home/wheel/retypeme
Expand Down
2 changes: 1 addition & 1 deletion deploy/templates/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- redis

ui:
image: retypeme/retypeme-frontend:{{ version }}
image: retypeme/retypeme-frontend-{{ env }}:{{ version }}
restart: always
ports:
- "3001:3000"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
# context: ./frontend
# args:
# NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY: ${NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY}
# NEXT_PUBLIC_API_DOMAIN: ${NEXT_PUBLIC_API_DOMAIN}
depends_on:
- api

Expand Down
3 changes: 3 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM node:21.4.0-alpine AS build
ARG NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY
ENV NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY ${NEXT_PUBLIC_ENV_LOCAL_INFURA_AMOY_API_KEY}

ARG NEXT_PUBLIC_API_DOMAIN
ENV NEXT_PUBLIC_API_DOMAIN ${NEXT_PUBLIC_API_DOMAIN}

WORKDIR /app

# Copy package.json and package-lock.json to install dependencies
Expand Down
27 changes: 15 additions & 12 deletions frontend/src/app/api/api-domain-service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
const domain = process.env.NEXT_PUBLIC_API_DOMAIN;

export default class ApiDomainService {
private readonly uiDomain: string;
private readonly domains: Map<string, string>;

private readonly wsUrl;
private readonly restUrl;

constructor() {
this.uiDomain = window.location.hostname;
this.domains = new Map([
["retypeme.apozdniakov.com", "retypeme-api.apozdniakov.com"],
["retypeme.vercel.app", "retypeme-api.apozdniakov.com"],
["retypeme.xyz", "app.retypeme.xyz"],
]);
console.log("API_DOMAIN: ", domain);

this.wsUrl = this.getUrl(true);
this.restUrl = this.getUrl(false);

console.log("WebSocket URL: ", this.wsUrl);
console.log("REST URL: ", this.restUrl);
}

private getUrl(isWebSocket: boolean): string {
let domain = this.domains.get(this.uiDomain);
let api = ""
if (domain === undefined) {
if (domain === undefined || domain.includes("localhost")) {
api = isWebSocket ? "ws://localhost:8080/api/ws" : "http://localhost:8080/api";
} else {
api = isWebSocket ? `wss://${domain}/api/ws` : `https://${domain}/api`;
Expand All @@ -23,10 +26,10 @@ export default class ApiDomainService {
}

getWebSocketUrl(): string {
return this.getUrl(true);
return this.wsUrl;
}

getRestUrl(): string {
return this.getUrl(false);
return this.restUrl;
}
}

0 comments on commit 2ff791e

Please sign in to comment.