From 5981234eb6a50afd1df43e3baea133114b1c08f1 Mon Sep 17 00:00:00 2001 From: Mark Kibara Date: Mon, 19 Feb 2024 17:12:04 +0300 Subject: [PATCH 01/11] Add entrypoint.sh --- entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..a9800eb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +pm2 start npm -- run dev +pm2 logs \ No newline at end of file From f901a70df50e195448830dc0c6ef6e29f04671b3 Mon Sep 17 00:00:00 2001 From: Mark Kibara Date: Mon, 19 Feb 2024 17:12:18 +0300 Subject: [PATCH 02/11] Add Dockerfile --- Dockerfile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..88fc387 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# Choose the Image which has Node installed already +FROM node:18.17-alpine + +# make the 'app' folder the current working directory +WORKDIR /app + +# copy both 'package.json' and 'package-lock.json' (if available) +COPY package*.json ./ + +# install project dependencies +RUN npm install + +RUN npm install pm2@latest -g + +# copy project files and folders to the current working directory +COPY . . + +# specifies that the container will listen on port 3000 +EXPOSE 3000 + +# specifies the command to run when the Docker image is started +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file From 08bc16e392745811251c6b63d1522161c9c5a1f5 Mon Sep 17 00:00:00 2001 From: Mark Kibara Date: Mon, 19 Feb 2024 17:13:04 +0300 Subject: [PATCH 03/11] Add comments to entrypoint.sh --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index a9800eb..555270e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,7 @@ #!/bin/sh +# run npm run dev through pm2 pm2 start npm -- run dev + +# show logs pm2 logs \ No newline at end of file From 90306af65584f21c6ec1a9e59ae4709f48c60f73 Mon Sep 17 00:00:00 2001 From: Mark Kibara Date: Mon, 19 Feb 2024 17:22:59 +0300 Subject: [PATCH 04/11] Add Docker commands --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c403366..c04f6b0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ pnpm dev bun dev ``` +If you are using Docker: + +```bash +docker build -t . + +docker run --name -p 3000:3000 -d +``` + Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. From c5f599ee6cdcc142930e6fcd0fc51891657eef8a Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 16:48:23 +0300 Subject: [PATCH 05/11] update Dockerfile, add docker-compose, add Makefile --- .dockerignore | 26 ++++++++++++++++++++++++++ Dockerfile | 43 ++++++++++++++++++++++++++++++++++--------- Makefile | 10 ++++++++++ docker-compose.yml | 6 ++++++ 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d4d8f0e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# Include files that you wouldn't want included in your container + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/build +**/dist +LICENSE +README.md +**/public/__env.js \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 88fc387..8644b9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,47 @@ -# Choose the Image which has Node installed already -FROM node:18.17-alpine +FROM node:18-alpine as base + +RUN apk add --no-cache g++ make py3-pip libc6-compat -# make the 'app' folder the current working directory WORKDIR /app -# copy both 'package.json' and 'package-lock.json' (if available) COPY package*.json ./ -# install project dependencies +FROM base as builder + +WORKDIR /app + +COPY . . +# Install project dependencies RUN npm install +RUN npm run build + +FROM base as production + +WORKDIR /app + +ENV NODE_ENV=production +# Install only production dependencies +RUN npm ci --only=production + +# Install pm2 process manager RUN npm install pm2@latest -g -# copy project files and folders to the current working directory -COPY . . +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 + +USER nextjs + +# Copy necessary files from builder stage +COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +COPY --from=builder --chown=nextjs:nodejs /app/next.config.mjs ./ +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/public ./public +COPY --from=builder /app/.env.production ./.env -# specifies that the container will listen on port 3000 EXPOSE 3000 # specifies the command to run when the Docker image is started -ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["./entrypoint.sh"] + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..669e4c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +SERVICE_NAME = aws-rstart-labs + +start-app: + docker-compose up + +tear-app: + docker-compose down --rmi $(SERVICE_NAME) + +# Phony targets to avoid conflicts with file names +.PHONY: start-app tear-app \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9c3e176 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3" +services: + aws-rstart-labs: + build: . + ports: + - "3000:3000" From f305d84e9fc9d76bbadb9863178edb688eb57fa6 Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 20:07:28 +0300 Subject: [PATCH 06/11] update README file, improve Docker container build process --- .dockerignore | 2 +- CODEOWNERS | 2 ++ CONTRIBUTING.md | 5 ++++ Dockerfile | 10 +++----- Makefile | 6 ++--- README.md | 64 +++++++++++++++++++++++++++++++------------------ entrypoint.sh | 6 ++--- 7 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 CODEOWNERS create mode 100644 CONTRIBUTING.md diff --git a/.dockerignore b/.dockerignore index d4d8f0e..047eb2c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,4 +23,4 @@ **/dist LICENSE README.md -**/public/__env.js \ No newline at end of file +**/public/__env.js diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..0b25239 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +# These owners will be the default owners for everything in the repo. +* @muriukialex @effiecancode diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..35c1043 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,5 @@ +## Contributing Guide + +- Fork the application, add your changes and make a [PR/MR](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) + +Contributions are highly welcome! \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8644b9a..57ce3a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ FROM node:18-alpine as base -RUN apk add --no-cache g++ make py3-pip libc6-compat - WORKDIR /app COPY package*.json ./ @@ -22,10 +20,7 @@ WORKDIR /app ENV NODE_ENV=production # Install only production dependencies -RUN npm ci --only=production - -# Install pm2 process manager -RUN npm install pm2@latest -g +RUN npm ci --omit=dev RUN addgroup -g 1001 -S nodejs RUN adduser -S nextjs -u 1001 @@ -38,7 +33,8 @@ COPY --from=builder --chown=nextjs:nodejs /app/next.config.mjs ./ COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/public ./public -COPY --from=builder /app/.env.production ./.env +COPY --from=builder /app/.env.local ./.env +COPY --from=builder /app/entrypoint.sh ./entrypoint.sh EXPOSE 3000 diff --git a/Makefile b/Makefile index 669e4c0..ad05635 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ -SERVICE_NAME = aws-rstart-labs - start-app: docker-compose up tear-app: - docker-compose down --rmi $(SERVICE_NAME) + docker-compose down --rmi all # Phony targets to avoid conflicts with file names -.PHONY: start-app tear-app \ No newline at end of file +.PHONY: start-app tear-app diff --git a/README.md b/README.md index c04f6b0..5c0db35 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,36 @@ -This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). +# Keep Track of AWS r/Start Labs + +- This application is designed to help AWS r/Start students to keep track of their AWS r/Start Labs. + +## Overview + +### Sign In +- Sign In with Google + +### Track Labs as Completed + +### Update Lab Completed Status + ## Getting Started -First, run the development server: +1. Clone the project + ```bash + git clone https://github.com/muriukialex/aws-rstart-labs.git +``` + +2. Install dependencies +```bash +npm install +``` + +3. Update your `.env.local` file with your enviroment variables which also includes a [MONGODB_URI](https://www.mongodb.com/basics/mongodb-connection-string#:~:text=How%20to%20get%20your%20MongoDB,connection%20string%20for%20your%20cluster.) +```bash +cp .env.example .env.local +``` +NB: Ensure you update your environent variables before starting the server + +3. Run the development server: ```bash npm run dev @@ -14,31 +42,21 @@ pnpm dev bun dev ``` +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + If you are using Docker: +Ensure you have [make](https://www.gnu.org/software/make/manual/make.html) installed `make --version` +- Build and run the Docker container ```bash -docker build -t . - -docker run --name -p 3000:3000 -d +make start-app ``` -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. - -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. - -This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. - -## Learn More - -To learn more about Next.js, take a look at the following resources: - -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. - -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! - -## Deploy on Vercel +- Tear down the Docker container +```bash +make tear-app +``` -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. +## Contributing +- See [CONTRIBUTING.md](https://github.com/muriukialex/aws-rstart-labs/blob/main/CONTRIBUTING.md) instructions on how to contribute. -Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/entrypoint.sh b/entrypoint.sh index 555270e..598d887 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -# run npm run dev through pm2 -pm2 start npm -- run dev +# run npm run start through pm2 +pm2 start npm -- run start # show logs -pm2 logs \ No newline at end of file +pm2 logs From ccb7f5a10fe2210a65929186e4d64b4333c01d2e Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 20:09:16 +0300 Subject: [PATCH 07/11] fix URL path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c0db35..644f2f5 100644 --- a/README.md +++ b/README.md @@ -58,5 +58,5 @@ make tear-app ``` ## Contributing -- See [CONTRIBUTING.md](https://github.com/muriukialex/aws-rstart-labs/blob/main/CONTRIBUTING.md) instructions on how to contribute. +- See [CONTRIBUTING.md](https://github.com/muriukialex/aws-rstart-labs/main/CONTRIBUTING.md) instructions on how to contribute. From 0d9cfa0ee0fdc34f95ba25b0e9634b8ba9002502 Mon Sep 17 00:00:00 2001 From: "alex.muriuki" Date: Sat, 24 Feb 2024 20:14:45 +0300 Subject: [PATCH 08/11] Update README.md Update section screenshots --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 644f2f5..35920d9 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,23 @@ ## Overview ### Sign In -- Sign In with Google +Sign In with Google + +![sign-in(light)](https://github.com/muriukialex/aws-rstart-labs/assets/51236424/d185ecd5-0b85-47e4-8a19-8f8d06cd2d1a) ### Track Labs as Completed +Light Theme Option + +![Screenshot 2024-02-24 192722](https://github.com/muriukialex/aws-rstart-labs/assets/51236424/ddda199b-b43d-42b6-b6ff-e230567c76ac) + +Dark Theme Option + + +![Screenshot 2024-02-24 192910](https://github.com/muriukialex/aws-rstart-labs/assets/51236424/c54117b1-8f43-44ba-93ae-918200c8888a) ### Update Lab Completed Status +![Screenshot 2024-02-24 193020](https://github.com/muriukialex/aws-rstart-labs/assets/51236424/e14890c5-acea-41f4-ae2f-92ceb8a68d1a) ## Getting Started From b2f56aeafd8fad86b8ecaa2e33001a96f8a59cc8 Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 20:16:54 +0300 Subject: [PATCH 09/11] update code owners file --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 0b25239..39ea878 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1,2 @@ # These owners will be the default owners for everything in the repo. -* @muriukialex @effiecancode +* @muriukialex @effiecancode @Topsideboss2 \ No newline at end of file From 6e16f8507f8fc6a48050348d4b4d865288e518c6 Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 20:22:23 +0300 Subject: [PATCH 10/11] add extra line --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 39ea878..fc84947 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1,2 @@ # These owners will be the default owners for everything in the repo. -* @muriukialex @effiecancode @Topsideboss2 \ No newline at end of file +* @muriukialex @effiecancode @Topsideboss2 From d502d93487750df6ca999174544687d79163fa37 Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 20:34:37 +0300 Subject: [PATCH 11/11] update error value on successful request --- hooks/useUserLabsData.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hooks/useUserLabsData.tsx b/hooks/useUserLabsData.tsx index 3b5d009..1581796 100644 --- a/hooks/useUserLabsData.tsx +++ b/hooks/useUserLabsData.tsx @@ -17,16 +17,14 @@ const useUserLabsData = ({ email }: { email?: string | null }) => { try { const response = await getLabs({ email }) const responseData = response.data + setError(null) // update the error value to null setData(responseData) - setIsLoading({ - status: "idle", - }) } catch (error) { const errorResponse = error as ErrorResponse if (errorResponse) { setError(errorResponse) } - + } finally { setIsLoading({ status: "idle", })