Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git work flow Master #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Build and Push Docker Images

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
REPOSITORY: eshietiy
FRONTEND_IMAGE_NAME: stage02_frontend
BACKEND_IMAGE_NAME: stage02_backend
TAG_NAME: latest

jobs:
build_backend:
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: Add SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Clone env config repository
run: git clone https://github.com/EshietIy/stage02.git

- name: Build Docker Image for backend
working-directory: ./backend
run: |
docker build \
--build-arg ENV_FILE=../stage02/backend/.env \
-t "${{ env.BACKEND_IMAGE_NAME }}:latest" \
.

- name: Push Docker Image to Docker Hub
run: |
docker tag ${{ env.BACKEND_IMAGE_NAME }}:latest ${{ env.REPOSITORY }}/${{ env.BACKEND_IMAGE_NAME }}:${{ env.TAG_NAME }}
docker push ${{ env.REPOSITORY }}/${{ env.BACKEND_IMAGE_NAME }}:${{ env.TAG_NAME }}

- name: Post cleanup
run: docker logout

build_frontend:
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: Add SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Clone env config repository
run: git clone https://github.com/EshietIy/stage02.git

- name: Build Docker Image for frontend
working-directory: ./frontend
run: |
docker build \
--build-arg ENV_FILE=../stage02/frontend/.env \
-t "${{ env.FRONTEND_IMAGE_NAME }}:latest" \
.

- name: Push Docker Image to Docker Hub
run: |
docker tag ${{ env.FRONTEND_IMAGE_NAME }}:latest ${{ env.REPOSITORY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ env.TAG_NAME }}
docker push ${{ env.REPOSITORY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ env.TAG_NAME }}

- name: Post cleanup
run: docker logout
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./backend/.env
./frontend/.env
33 changes: 0 additions & 33 deletions backend/.env

This file was deleted.

1 change: 1 addition & 0 deletions backend/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.0
23 changes: 23 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion frontend/.env

This file was deleted.

28 changes: 28 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;"]
11 changes: 11 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}