Skip to content

Commit

Permalink
feat: The project is Dockerize and github actions is added to push do…
Browse files Browse the repository at this point in the history
…cker image to dockerhub.
  • Loading branch information
Suraj-kumar00 committed Oct 9, 2024
1 parent bbf2c2a commit 581a0f2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ celerybeat.pid
*.sage.py

# Environments
.env.local
.env
.venv
env/
Expand Down
16 changes: 16 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
12 changes: 6 additions & 6 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))

20 changes: 20 additions & 0 deletions front-end-nextjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 581a0f2

Please sign in to comment.