Skip to content

Commit

Permalink
added locale init containers
Browse files Browse the repository at this point in the history
  • Loading branch information
jagankumar-egov committed Jul 3, 2024
1 parent 4aa69b5 commit 087ff53
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/buildSampleUI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ jobs:
--tag $IMAGE_TAG
echo "::set-output name=image_name::$IMAGE_TAG"
- name: Build the locale migration Docker image
id: docker_db_build
working-directory: ./micro-frontends/sample/fetch-locales
run: |
IMAGE_TAG=egovio/sample-ui-db:${{ env.BRANCH_NAME }}-${{ env.COMMIT_ID }}-${{ env.ACTION_NUMBER }}
docker build . \
--file Dockerfile \
--tag $IMAGE_TAG
echo "::set-output name=db_image_name::$IMAGE_TAG"
- name: Login to Docker Hub and Push Docker Image
working-directory: ./micro-frontends/sample
env:
Expand All @@ -44,4 +54,18 @@ jobs:
# Push the image to Docker Hub
docker push $IMAGE_NAME
echo "Docker image pushed: $IMAGE_NAME"
echo "Docker image pushed: $IMAGE_NAME"
- name: Login to Docker Hub and Push DB Migration Docker Image
working-directory: ./micro-frontends/sample/fetch-locales
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DB_IMAGE_NAME: ${{ steps.docker_db_build.outputs.db_image_name }}
run: |
# Authenticate with Docker Hub
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# Push the image to Docker Hub
docker push $DB_IMAGE_NAME
echo "Docker image pushed: $DB_IMAGE_NAME"
17 changes: 17 additions & 0 deletions micro-frontends/sample/fetch-locales/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use Node.js base image
FROM node:20 AS fetch-locales

# Set working directory
WORKDIR /fetcher

# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy fetch-locales script
COPY fetch-locales.js .

# Set command to run the fetch-locales script
CMD ["node", "fetch-locales.js"]
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import axios from 'axios';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

// __filename and __dirname are not available in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const locales = [
{ lang: 'en', url: 'https://api.example.com/locales/en' },
{ lang: 'fr', url: 'https://api.example.com/locales/fr' },
{ lang: 'de', url: 'https://api.example.com/locales/de' }
{ lang: 'en', url: process.env.LOCALE_API_URL_EN },
{ lang: 'fr', url: process.env.LOCALE_API_URL_FR },
{ lang: 'de', url: process.env.LOCALE_API_URL_DE }
];

const fetchLocales = async () => {
for (const locale of locales) {
try {
const response = await axios.get(locale.url);
const dir = path.join(__dirname, 'public', 'locales', locale.lang);
const dir = path.join('/locales', locale.lang);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
Expand Down
18 changes: 18 additions & 0 deletions micro-frontends/sample/fetch-locales/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "fetch-locales",
"version": "1.0.0",
"description": "A script to fetch locales from an API and store them",
"main": "fetch-locales.js",
"type": "module",
"scripts": {
"start": "node fetch-locales.js"
},
"dependencies": {
"axios": "^0.27.2"
},
"engines": {
"node": ">=20"
},
"author": "",
"license": "ISC"
}

0 comments on commit 087ff53

Please sign in to comment.