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 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 c3af24175..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 -POSTGRES_USER=app -POSTGRES_PASSWORD=changethis123 - 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/.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 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