Skip to content

Commit

Permalink
Merge pull request #30 from gilmaimon/rewrite-backend
Browse files Browse the repository at this point in the history
Rewrite backend
  • Loading branch information
gilmaimon authored Jul 26, 2024
2 parents 40620c9 + ff28237 commit 241c561
Show file tree
Hide file tree
Showing 56 changed files with 17,485 additions and 17,606 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Push Docker Image

on:
push:
branches:
- '**' # Triggers on push to any branch
pull_request:
branches:
- master # Triggers on PR to master branch
workflow_dispatch: # Manually trigger the workflow

jobs:
build:
if: github.ref != 'refs/heads/master'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
run: docker build -t server .

deploy:
needs: build # Ensure deploy job waits for build job
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push Docker image
run: docker push server:latest
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Stage 1: Build React App
FROM node:22-alpine AS frontend-builder

# Set the working directory
WORKDIR /app

# Copy the React app source code
COPY client/package.json client/package-lock.json ./

# Install dependencies
RUN npm install

# Copy the rest of the React app source code
COPY client/src/ /app/src
COPY client/public/ /app/public

RUN npm run build

# Stage 2: Build the Go binary
FROM golang:1.20-alpine AS builder

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy go.mod and go.sum files
COPY server-v2/go.mod server-v2/go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source code into the container
COPY server-v2 ./

# Build the Go app
RUN go build -o server .

# Stage 3: Run the Go binary
FROM alpine:latest

# Set the Current Working Directory inside the container
WORKDIR /root/

# Copy configuration and assets
COPY config-prod.yaml ./server.yaml
COPY server-v2/Verdana.ttf ./

# Copy the static content
COPY --from=frontend-builder /app/build/ /app/static/

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/server .

# Expose http ports to the outside world
EXPOSE 80
EXPOSE 443

# Command to run the executable
CMD ["./server"]
9 changes: 9 additions & 0 deletions build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -ex

docker build -t server .

docker run -p 80:80 \
-p 443:443 \
-v ./cert.pem:/certs/ardu-badge.cert \
-v ./privkey.pem:/certs/ardu-badge.key \
server
3 changes: 3 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.


.idea/

# dependencies
/node_modules
/.pnp
Expand Down
Loading

0 comments on commit 241c561

Please sign in to comment.