Skip to content

Commit

Permalink
Merge pull request #35 from lalithkota/1.0
Browse files Browse the repository at this point in the history
Repo and module renamed
  • Loading branch information
lalithkota authored Jan 6, 2025
2 parents fd20288 + c78f504 commit 856f807
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_BASE_PATH="/selfservice"
NEXT_PUBLIC_BASE_API_PATH="/v1/selfservice"
20 changes: 7 additions & 13 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.docker_hub_organisation }}
SELFSERVICE_SERVICE_NAME: "openg2p-selfservice-ui"
SERVICE_NAME: "openg2p-beneficiary-portal-ui"
steps:
- uses: actions/checkout@v3
- name: Setup branch and env
Expand All @@ -25,22 +25,17 @@ jobs:
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build docker
run: |
SELFSERVICE_IMAGE_ID=$NAMESPACE/$SELFSERVICE_SERVICE_NAME
IMAGE_ID=$NAMESPACE/$SERVICE_NAME
# Change all uppercase to lowercase
SELFSERVICE_IMAGE_ID=$(echo $SELFSERVICE_IMAGE_ID | tr '[A-Z]' '[a-z]')
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo SELFSERVICE_IMAGE_ID=$SELFSERVICE_IMAGE_ID
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo "SELFSERVICE_IMAGE_ID=$SELFSERVICE_IMAGE_ID" >> $GITHUB_ENV
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
docker build . \
--file Dockerfile \
--tag $SELFSERVICE_IMAGE_ID:$VERSION
docker build . \
--file Dockerfile.no-runtime-build \
--tag $SELFSERVICE_IMAGE_ID:$VERSION-no-runtime-build
docker build . --file Dockerfile --tag $IMAGE_ID:$VERSION
- name: Docker login
run: |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
Expand All @@ -50,5 +45,4 @@ jobs:
fi
- name: Docker Push images
run: |
docker push $SELFSERVICE_IMAGE_ID:$VERSION
docker push $SELFSERVICE_IMAGE_ID:$VERSION-no-runtime-build
docker push $IMAGE_ID:$VERSION
49 changes: 33 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
FROM node:18-alpine AS base

RUN apk add bash

FROM base AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
WORKDIR /app

COPY package.json package-lock.json* ./

RUN npm ci

COPY . .
RUN ./docker-env-replace.sh .env.prod .env.local

ENV NEXT_TELEMETRY_DISABLED 1
RUN npm run build

FROM base AS runner
WORKDIR /app

RUN chown -R nextjs:nodejs /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

USER nextjs
RUN mkdir .next
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/.env.prod .
COPY --from=builder --chown=nextjs:nodejs /app/docker-entrypoint.sh .

# Install dependencies based on the preferred package manager
COPY --chown=nextjs:nodejs package.json package-lock.json* ./
RUN npm ci
RUN npm i sharp

RUN chown nextjs:nodejs /app

COPY --chown=nextjs:nodejs . .
USER nextjs

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV HOSTNAME="0.0.0.0"
ENV PORT=3000
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production
ENV PORT 3000
ENV HOSTNAME 0.0.0.0

EXPOSE 3000

CMD npm run build && npm run start
ENTRYPOINT [ "./docker-entrypoint.sh" ]
CMD node server.js
34 changes: 0 additions & 34 deletions Dockerfile.no-runtime-build

This file was deleted.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# OpenG2P Beneficiary Portal

OpenG2P beneficiary self service portal

## Developer Notes

- For local development.
- Install Node, Npm, Npx.
- Install dependencies
```sh
npm ci
```
- Create a `.env.local` file with the following content. Edit the below API base path appropriately.
```sh
NEXT_PUBLIC_BASE_PATH=""
NEXT_PUBLIC_BASE_API_PATH="http://localhost:8000/"
```
- Run the following to start the app
```sh
npm run dev
```
- Open [http://localhost:3000](http://localhost:3000) on browser.
25 changes: 25 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

WORKDIR="/app"
ENV_FILE=$WORKDIR/.env.prod

IFS=$'\n' next_env_vars=($(awk 'BEGIN{for(v in ENVIRON) print v}' | grep "^NEXT_PUBLIC_"))
for env_var in ${next_env_vars[@]}; do
file_env_var_line=$(grep "${env_var}=" $ENV_FILE)
if ! [ -z $file_env_var_line ]; then
sed -i "s|$file_env_var_line||g" $ENV_FILE
fi
done

set -a
source $ENV_FILE
set +a

IFS=$'\n' next_env_vars=($(awk 'BEGIN{for(v in ENVIRON) print v}' | grep "^NEXT_PUBLIC_"))
for env_var in ${next_env_vars[@]}; do
for file in $(find $WORKDIR -name "node_modules" -prune -o -type f -exec grep -l "/@$env_var@" {} \;); do
sed -i "s|/@$env_var@|${!env_var}|g" $file
done
done

exec "$@"
15 changes: 15 additions & 0 deletions docker-env-replace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

input_file=$1
output_file=$2

while read line; do
# Skip empty lines and comments
if [[ -z "$line" ]] || [[ "$line" =~ ^# ]]; then
echo "$line" >> $output_file
continue
fi

key=$(echo "$line" | cut -d'=' -f1)
echo "$key=/@$key@" >> $output_file
done < $input_file
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const withNextIntl = createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {
basePath: process.env.NEXT_PUBLIC_BASE_PATH || "",
output: "standalone",
};

module.exports = withNextIntl(nextConfig);
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openg2p-selfservice-ui",
"version": "0.1.0",
"name": "openg2p-beneficiary-portal-ui",
"version": "1.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/login/loginbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function LoginBox() {
{t("Password")}
</label>
<div className="" style={{color: "#6569C7", fontWeight: "500", letterSpacing: "0px"}}>
<a href="/selfservice/en/login">{t("Reset Password")}</a>
<a href={prefixBasePath("/en/login")}>{t("Reset Password")}</a>
</div>
</div>
<input
Expand Down

0 comments on commit 856f807

Please sign in to comment.