This commit is contained in:
Luke Gustafson
2024-11-27 01:07:44 +00:00
parent b16bc1a5bb
commit 5dedadddf9
9 changed files with 146 additions and 33 deletions

View File

@@ -12,20 +12,29 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install dependencies and build frontend - name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install and Build Frontend
run: | run: |
cd frontend cd frontend
npm install npm install
npm run build npm run build
ls -R . # Debugging: List files in frontend after build
- name: Debug workspace structure
run: ls -R /github/workspace # Debugging: Verify where `dist` is created
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
- name: Set up Docker login to GHCR - name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Registry (GHCR)
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
registry: ghcr.io registry: ghcr.io
@@ -33,8 +42,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image - name: Build Docker image
run: | run: docker build -f Dockerfile -t ghcr.io/${{ github.repository_owner }}/ssh-project:${{ github.run_id }} .
docker build -f docker/Dockerfile . --tag ghcr.io/$REPO_NAME/ssh-project:$DATE_TAG
- name: Push Docker image to GHCR - name: Push Docker image to GHCR
run: docker push ghcr.io/$REPO_NAME/ssh-project:$DATE_TAG run: docker push ghcr.io/${{ github.repository_owner }}/ssh-project:${{ github.run_id }}

View File

@@ -0,0 +1,48 @@
name: Build and Push Docker Image
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install and Build Frontend
run: |
cd frontend
npm install
npm run build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Registry (GHCR)
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: docker build -f Dockerfile -t ghcr.io/${{ github.repository_owner }}/ssh-project:${{ github.run_id }} .
- name: Push Docker image to GHCR
run: docker push ghcr.io/${{ github.repository_owner }}/ssh-project:${{ github.run_id }}

View File

@@ -1 +1 @@
{"version":1,"resource":"vscode-remote://coder.karmaashomepage.online/home/bugattiguy527/.github/workflows/docker-image.yml","entries":[{"id":"9X2e.yml","timestamp":1732667889336},{"id":"3EZP.yml","timestamp":1732667936044}]} {"version":1,"resource":"vscode-remote://coder.karmaashomepage.online/home/bugattiguy527/.github/workflows/docker-image.yml","entries":[{"id":"9X2e.yml","timestamp":1732667889336},{"id":"3EZP.yml","timestamp":1732667936044},{"id":"jUoS.yml","source":"undoRedo.source","timestamp":1732667990352},{"id":"YqrT.yml","timestamp":1732669649485}]}

View File

@@ -0,0 +1,41 @@
name: Build and Push Docker Image
on:
push:
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: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate docker tag
id: prep
run: |
echo "REPO_NAME=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "DATE_TAG=$(date +%s)" >> $GITHUB_ENV
- name: Build Docker image
run: docker build -f docker/Dockerfile . --tag ghcr.io/$REPO_NAME/ssh-project:$DATE_TAG
- name: Push Docker image to GHCR
run: docker push ghcr.io/$REPO_NAME/ssh-project:$DATE_TAG

View File

@@ -0,0 +1,23 @@
# Build frontend
FROM node:18-slim AS frontend-build
WORKDIR /app
COPY frontend/package*.json ./frontend/
RUN npm --prefix frontend install
COPY frontend/ ./frontend/
RUN npm --prefix frontend run build
# Build backend
FROM node:18-slim AS backend-build
WORKDIR /backend
COPY backend/package*.json ./
RUN npm install
COPY backend/ .
# Production image
FROM nginx:alpine
# Copy frontend static files to nginx folder
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
# Copy backend application
COPY --from=backend-build /backend /backend
# Start backend and frontend servers
CMD ["sh", "-c", "node /backend/server.js & nginx -g 'daemon off;'"]

View File

@@ -1 +1 @@
{"version":1,"resource":"vscode-remote://coder.karmaashomepage.online/home/bugattiguy527/docker/Dockerfile","entries":[{"id":"TUF1","timestamp":1732635492973},{"id":"8otg","timestamp":1732635506681},{"id":"XU8z","source":"undoRedo.source","timestamp":1732635515769},{"id":"ars1","timestamp":1732635532917},{"id":"8UPb","timestamp":1732635628577},{"id":"gWeB","timestamp":1732635658901},{"id":"Z5sv","source":"undoRedo.source","timestamp":1732635671649},{"id":"J4VB","timestamp":1732635674581},{"id":"eNc9","timestamp":1732651223530},{"id":"qz6w","timestamp":1732666102382},{"id":"dg9u","timestamp":1732666385636},{"id":"xeWT","timestamp":1732666594049},{"id":"VKz9","timestamp":1732666699486},{"id":"ohj0","timestamp":1732666756338},{"id":"YYfg","timestamp":1732666912166},{"id":"fk8j","source":"undoRedo.source","timestamp":1732666929490},{"id":"KzCQ","timestamp":1732666932302},{"id":"Ksxv","timestamp":1732666980583},{"id":"YyhO","timestamp":1732667021083},{"id":"fABD","timestamp":1732667045735},{"id":"9QEU","timestamp":1732667168771},{"id":"ZvDX","source":"undoRedo.source","timestamp":1732667172295},{"id":"b8fu","timestamp":1732667181363},{"id":"U8fB","timestamp":1732667377239},{"id":"qfRq","timestamp":1732667388987},{"id":"EPuH","timestamp":1732667567379},{"id":"ErcD","timestamp":1732667709908}]} {"version":1,"resource":"vscode-remote://coder.karmaashomepage.online/home/bugattiguy527/docker/Dockerfile","entries":[{"id":"TUF1","timestamp":1732635492973},{"id":"8otg","timestamp":1732635506681},{"id":"XU8z","source":"undoRedo.source","timestamp":1732635515769},{"id":"ars1","timestamp":1732635532917},{"id":"8UPb","timestamp":1732635628577},{"id":"gWeB","timestamp":1732635658901},{"id":"Z5sv","source":"undoRedo.source","timestamp":1732635671649},{"id":"J4VB","timestamp":1732635674581},{"id":"eNc9","timestamp":1732651223530},{"id":"qz6w","timestamp":1732666102382},{"id":"dg9u","timestamp":1732666385636},{"id":"xeWT","timestamp":1732666594049},{"id":"VKz9","timestamp":1732666699486},{"id":"ohj0","timestamp":1732666756338},{"id":"YYfg","timestamp":1732666912166},{"id":"fk8j","source":"undoRedo.source","timestamp":1732666929490},{"id":"KzCQ","timestamp":1732666932302},{"id":"Ksxv","timestamp":1732666980583},{"id":"YyhO","timestamp":1732667021083},{"id":"fABD","timestamp":1732667045735},{"id":"9QEU","timestamp":1732667168771},{"id":"ZvDX","source":"undoRedo.source","timestamp":1732667172295},{"id":"b8fu","timestamp":1732667181363},{"id":"U8fB","timestamp":1732667377239},{"id":"qfRq","timestamp":1732667388987},{"id":"EPuH","timestamp":1732667567379},{"id":"ErcD","timestamp":1732667709908},{"id":"EvMq","timestamp":1732669655605}]}

View File

@@ -1,30 +1,23 @@
FROM node:18-slim AS combined-build # Build frontend
FROM node:18-slim AS frontend-build
WORKDIR /app WORKDIR /app
# Copy and install frontend dependencies
COPY frontend/package*.json ./frontend/ COPY frontend/package*.json ./frontend/
WORKDIR /app/frontend RUN npm --prefix frontend install
RUN npm install COPY frontend/ ./frontend/
COPY frontend/ . RUN npm --prefix frontend run build
RUN npm run build
# Copy frontend build output to /app directory # Build backend
WORKDIR /app FROM node:18-slim AS backend-build
RUN mkdir -p /app/public WORKDIR /backend
COPY /app/dist /app/public
# Setup backend
COPY backend/package*.json ./ COPY backend/package*.json ./
RUN npm install RUN npm install
COPY backend/ . COPY backend/ .
# Setup Nginx to serve the React App # Production image
FROM nginx:alpine FROM nginx:alpine
COPY --from=combined-build /app/public /usr/share/nginx/html # Copy frontend static files to nginx folder
COPY --from=frontend-build /app/frontend/dist /usr/share/nginx/html
# Expose ports for frontend and backend # Copy backend application
EXPOSE 80 COPY --from=backend-build /backend /backend
EXPOSE 3001 # Start backend and frontend servers
CMD ["sh", "-c", "node /backend/server.js & nginx -g 'daemon off;'"]
# Run backend and frontend servers
CMD ["sh", "-c", "node /app/src/components/server.js & nginx -g 'daemon off;'"]