diff --git a/.github/workflows/build-docker.yaml b/.github/workflows/build-docker.yaml new file mode 100644 index 00000000..fa6bf72a --- /dev/null +++ b/.github/workflows/build-docker.yaml @@ -0,0 +1,24 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Login to DockerHub + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin + + - name: Build the Docker image + run: docker build -t surajkumar00/devops-url2qr-api . + + - name: Push the Docker image to DockerHub + run: docker push surajkumar00/devops-url2qr-api \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore index 6769e21d..0c6e9a55 100644 --- a/api/.gitignore +++ b/api/.gitignore @@ -120,6 +120,7 @@ celerybeat.pid *.sage.py # Environments +.env.local .env .venv env/ diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 00000000..f89f4a71 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.9 + +# Set up the work directory in the container +WORKDIR /usr/src/app # Ensure the path is correct with the leading slash + +# Copy the dependency files to the working directory +COPY requirements.txt ./ + +# Install the needed packages specified in the requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the content of local src directory to the working directory +COPY . . + +# Command to run the application +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/api/main.py b/api/main.py index d9d275b4..7ab1af14 100644 --- a/api/main.py +++ b/api/main.py @@ -26,10 +26,11 @@ # 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")) + 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 +bucket_name = 'devops-url2qr' # Add your bucket name here @app.post("/generate-qr/") async def generate_qr(url: str): @@ -54,12 +55,11 @@ async def generate_qr(url: str): 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') + # Upload to S3 without ACL + s3.put_object(Bucket=bucket_name, Key=file_name, Body=img_byte_arr, ContentType='image/png') # 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/front-end-nextjs/Dockerfile b/front-end-nextjs/Dockerfile new file mode 100644 index 00000000..cbccdbac --- /dev/null +++ b/front-end-nextjs/Dockerfile @@ -0,0 +1,20 @@ +FROM node:18-alpine AS base + +WORKDIR /app + +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ + +RUN \ +if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ +elif [ -f package-lock.json ]; then npm ci; \ +elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ +else echo "Lockfile not found." && exit 1; \ +fi + +COPY . . + +RUN npm run build + +EXPOSE 3000 + +CMD ["npm","start"] \ No newline at end of file