From d45134cb5a2c8d77cb69f91e3367d33bf40d452b Mon Sep 17 00:00:00 2001 From: Eshiet Date: Sun, 7 Jul 2024 15:41:38 +0100 Subject: [PATCH 1/3] updated --- backend/.env | 6 +++--- backend/.python-version | 1 + backend/Dockerfile | 23 +++++++++++++++++++++++ frontend/Dockerfile | 28 ++++++++++++++++++++++++++++ frontend/nginx.conf | 11 +++++++++++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 backend/.python-version create mode 100644 backend/Dockerfile create mode 100644 frontend/Dockerfile create mode 100644 frontend/nginx.conf diff --git a/backend/.env b/backend/.env index c3af24175..46699304b 100644 --- a/backend/.env +++ b/backend/.env @@ -27,7 +27,7 @@ SMTP_PORT=587 # Postgres POSTGRES_SERVER=localhost POSTGRES_PORT=5432 -POSTGRES_DB=app -POSTGRES_USER=app -POSTGRES_PASSWORD=changethis123 +POSTGRES_DB=app_db +POSTGRES_USER=admin +POSTGRES_PASSWORD=Bevcity01 diff --git a/backend/.python-version b/backend/.python-version new file mode 100644 index 000000000..30291cba2 --- /dev/null +++ b/backend/.python-version @@ -0,0 +1 @@ +3.10.0 diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..f3d4e58bc --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,23 @@ +# Use a lightweight base image +FROM python:3.10-slim + +# Updating libraries +RUN apt-get update && apt-get install -y \ + libpq-dev + +# Set working directory +WORKDIR /app + +# Install Poetry +RUN pip install poetry + +# Copy project files +COPY . . + +# Install dependencies (including poetry) +RUN poetry config virtualenvs.create true \ +&& poetry install --no-dev --no-interaction --no-ansi + +RUN chmod +x /app/prestart.sh +EXPOSE 8000 +ENTRYPOINT ["poetry", "run", "bash", "-c", "/app/prestart.sh && uvicorn app.main:app --host 0.0.0.0 --port 8000"] \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 000000000..113c20528 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,28 @@ +# Use the official Node.js image to build the React app +FROM node:16 AS build + +# Set the working directory +WORKDIR /app + +#Copy to working directory +COPY . . + +# Install dependencies +RUN npm install + +# Build the React app +RUN npm run build + +# Use the official Nginx image to serve the built app +FROM nginx:alpine + +# Copy the built React app from the previous stage +COPY --from=build /app/dist /usr/share/nginx/html + +COPY ./nginx.conf /etc/nginx/conf.d/default.conf + +# Expose port 80 to the outside world +EXPOSE 80 + +# Start Nginx server +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 000000000..e42859054 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,11 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri /index.html =404; + } + + include /etc/nginx/extra-conf.d/*.conf; +} \ No newline at end of file From 24283b1ea4d778a7c73ef5eb94cd1859546c6998 Mon Sep 17 00:00:00 2001 From: Eshiet Date: Sun, 7 Jul 2024 16:07:18 +0100 Subject: [PATCH 2/3] .env removed --- .gitignore | 2 ++ backend/.env | 33 --------------------------------- frontend/.env | 1 - 3 files changed, 2 insertions(+), 34 deletions(-) create mode 100644 .gitignore delete mode 100644 backend/.env delete mode 100644 frontend/.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f114f925e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +./backend/.env +./frontend/.env \ No newline at end of file diff --git a/backend/.env b/backend/.env deleted file mode 100644 index 46699304b..000000000 --- a/backend/.env +++ /dev/null @@ -1,33 +0,0 @@ -# Domain -# This would be set to the production domain with an env var on deployment -DOMAIN=localhost - -# Environment: local, staging, production -ENVIRONMENT=local - -PROJECT_NAME="Full Stack FastAPI Project" -STACK_NAME=full-stack-fastapi-project - -# Backend -BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173" -SECRET_KEY=changethis123 -FIRST_SUPERUSER=devops@hng.tech -FIRST_SUPERUSER_PASSWORD=devops#HNG11 -USERS_OPEN_REGISTRATION=True - -# Emails -SMTP_HOST= -SMTP_USER= -SMTP_PASSWORD= -EMAILS_FROM_EMAIL=info@example.com -SMTP_TLS=True -SMTP_SSL=False -SMTP_PORT=587 - -# Postgres -POSTGRES_SERVER=localhost -POSTGRES_PORT=5432 -POSTGRES_DB=app_db -POSTGRES_USER=admin -POSTGRES_PASSWORD=Bevcity01 - diff --git a/frontend/.env b/frontend/.env deleted file mode 100644 index 5934e2e7d..000000000 --- a/frontend/.env +++ /dev/null @@ -1 +0,0 @@ -VITE_API_URL=http://localhost:8000 From 3abf9490d6f50cf5f548b6a67f2924a9c9adcbbc Mon Sep 17 00:00:00 2001 From: Eshietly <67698120+EshietIy@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:36:08 +0100 Subject: [PATCH 3/3] Create docker-image.yml --- .github/workflows/docker-image.yml | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 000000000..259c685ab --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,39 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/fastapi-application:latest + + - name: Post cleanup + run: docker logout