From b2a846ff3e068a1bbcd3c728c708edf0e22b6d6b Mon Sep 17 00:00:00 2001 From: obinna Date: Thu, 6 Nov 2025 09:07:09 +0100 Subject: [PATCH 1/3] edited the dockerfile --- api/.env.example | 2 - api/.gitignore | 160 ------------------ api/main.py | 65 ------- api/requirements.txt | 24 --- api/test_main.py | 17 -- .../.github/workflows/build-docker.yaml | 19 +++ front-end-nextjs/dockerfile | 15 ++ 7 files changed, 34 insertions(+), 268 deletions(-) delete mode 100644 api/.env.example delete mode 100644 api/.gitignore delete mode 100644 api/main.py delete mode 100644 api/requirements.txt delete mode 100644 api/test_main.py create mode 100644 front-end-nextjs/.github/workflows/build-docker.yaml create mode 100644 front-end-nextjs/dockerfile diff --git a/api/.env.example b/api/.env.example deleted file mode 100644 index 6083f141..00000000 --- a/api/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -AWS_ACCESS_KEY=Your-AWS-Access-Key -AWS_SECRET_KEY=Your-AWS-Secret-Access-Key \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index 6769e21d..00000000 --- a/api/.gitignore +++ /dev/null @@ -1,160 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file diff --git a/api/main.py b/api/main.py deleted file mode 100644 index d9d275b4..00000000 --- a/api/main.py +++ /dev/null @@ -1,65 +0,0 @@ -from fastapi import FastAPI, HTTPException -from fastapi.middleware.cors import CORSMiddleware -import qrcode -import boto3 -import os -from io import BytesIO - -# Loading Environment variable (AWS Access Key and Secret Key) -from dotenv import load_dotenv -load_dotenv() - -app = FastAPI() - -# Allowing CORS for local testing -origins = [ - "http://localhost:3000" -] - -app.add_middleware( - CORSMiddleware, - allow_origins=origins, - allow_methods=["*"], - allow_headers=["*"], -) - -# AWS S3 Configuration -s3 = boto3.client( - 's3', - aws_access_key_id= os.getenv("AWS_ACCESS_KEY"), - aws_secret_access_key= os.getenv("AWS_SECRET_KEY")) - -bucket_name = 'YOUR_BUCKET_NAME' # Add your bucket name here - -@app.post("/generate-qr/") -async def generate_qr(url: str): - # Generate QR Code - qr = qrcode.QRCode( - version=1, - error_correction=qrcode.constants.ERROR_CORRECT_L, - box_size=10, - border=4, - ) - qr.add_data(url) - qr.make(fit=True) - - img = qr.make_image(fill_color="black", back_color="white") - - # Save QR Code to BytesIO object - img_byte_arr = BytesIO() - img.save(img_byte_arr, format='PNG') - img_byte_arr.seek(0) - - # Generate file name for S3 - file_name = f"qr_codes/{url.split('//')[-1]}.png" - - try: - # Upload to S3 - s3.put_object(Bucket=bucket_name, Key=file_name, Body=img_byte_arr, ContentType='image/png', ACL='public-read') - - # Generate the S3 URL - s3_url = f"https://{bucket_name}.s3.amazonaws.com/{file_name}" - return {"qr_code_url": s3_url} - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) - \ No newline at end of file diff --git a/api/requirements.txt b/api/requirements.txt deleted file mode 100644 index 41984a1c..00000000 --- a/api/requirements.txt +++ /dev/null @@ -1,24 +0,0 @@ -annotated-types==0.6.0 -anyio==3.7.1 -boto3==1.34.11 -botocore==1.34.11 -click==8.1.7 -exceptiongroup==1.2.0 -fastapi==0.105.0 -h11==0.14.0 -idna==3.6 -jmespath==1.0.1 -pillow==10.2.0 -pydantic==2.5.2 -pydantic_core==2.14.5 -pypng==0.20220715.0 -python-dateutil==2.8.2 -python-dotenv==1.0.0 -qrcode==7.4.2 -s3transfer==0.10.0 -six==1.16.0 -sniffio==1.3.0 -starlette==0.27.0 -typing_extensions==4.9.0 -urllib3==1.26.18 -uvicorn==0.24.0.post1 diff --git a/api/test_main.py b/api/test_main.py deleted file mode 100644 index 78fc9741..00000000 --- a/api/test_main.py +++ /dev/null @@ -1,17 +0,0 @@ -from fastapi.testclient import TestClient -from main import app - -client = TestClient(app) - -def test_generate_qr(): - url = "http://example.com" - response = client.post("/generate-qr/", json={"url": url}) - - assert response.status_code == 200 - assert "qr_code_url" in response.json() - -def test_generate_qr_invalid_url(): - url = "invalid-url" - response = client.post("/generate-qr/", json={"url": url}) - - assert response.status_code == 422 # FastAPI validation error \ No newline at end of file diff --git a/front-end-nextjs/.github/workflows/build-docker.yaml b/front-end-nextjs/.github/workflows/build-docker.yaml new file mode 100644 index 00000000..0f93804f --- /dev/null +++ b/front-end-nextjs/.github/workflows/build-docker.yaml @@ -0,0 +1,19 @@ +name: Build and Publish image to Docker Hub +on: + push: + branches: + - main + +jobs: + Build_and_publish_images: + runs-on: ubuntu-lastest + steps: + - name: checkout + uses: action/checkout@v4 + + - name: build image + run: docker build -t obinnanwaneri/docker-frontend:lastest ./front-end-nextjs + + - name: push images to docker hub + run: | + docker push obinnanwaneri/docker-frontend:lastest diff --git a/front-end-nextjs/dockerfile b/front-end-nextjs/dockerfile new file mode 100644 index 00000000..9dc2e733 --- /dev/null +++ b/front-end-nextjs/dockerfile @@ -0,0 +1,15 @@ +FROM node:18-alpine AS base + +WORKDIR /app + +COPY package-lock.json* . + +RUN npm install + +COPY . . + +RUN npm run build + +EXPOSE 3000 + +CMD ["npm", "start"] \ No newline at end of file From c3f1cf7a5910101cdf957a7e6016bed13bf94036 Mon Sep 17 00:00:00 2001 From: obinna Date: Thu, 6 Nov 2025 09:16:25 +0100 Subject: [PATCH 2/3] Edited dockerfile --- front-end-nextjs/dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front-end-nextjs/dockerfile b/front-end-nextjs/dockerfile index 9dc2e733..cd4fc1ff 100644 --- a/front-end-nextjs/dockerfile +++ b/front-end-nextjs/dockerfile @@ -2,7 +2,7 @@ FROM node:18-alpine AS base WORKDIR /app -COPY package-lock.json* . +COPY package.json . RUN npm install From 84ffd364d4b9522f07bfe9d0fe1c4a6f59ed2e54 Mon Sep 17 00:00:00 2001 From: obinna Date: Sun, 9 Nov 2025 17:53:04 +0100 Subject: [PATCH 3/3] implements dynamic tagging --- front-end-nextjs/.github/workflows/build-docker.yaml | 8 ++++---- front-end-nextjs/dockerfile | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/front-end-nextjs/.github/workflows/build-docker.yaml b/front-end-nextjs/.github/workflows/build-docker.yaml index 0f93804f..0611d3ff 100644 --- a/front-end-nextjs/.github/workflows/build-docker.yaml +++ b/front-end-nextjs/.github/workflows/build-docker.yaml @@ -6,14 +6,14 @@ on: jobs: Build_and_publish_images: - runs-on: ubuntu-lastest + runs-on: ubuntu-22.04 steps: - name: checkout - uses: action/checkout@v4 + uses: actions/checkout@v4 - name: build image - run: docker build -t obinnanwaneri/docker-frontend:lastest ./front-end-nextjs + run: docker build -t obinnanwaneri/docker-frontend:${{github.sha}} ./front-end-nextjs - name: push images to docker hub run: | - docker push obinnanwaneri/docker-frontend:lastest + docker push obinnanwaneri/docker-frontend:${{github.sha}} diff --git a/front-end-nextjs/dockerfile b/front-end-nextjs/dockerfile index cd4fc1ff..647406ed 100644 --- a/front-end-nextjs/dockerfile +++ b/front-end-nextjs/dockerfile @@ -4,7 +4,7 @@ WORKDIR /app COPY package.json . -RUN npm install +RUN npm ci COPY . .