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

Rewrite backend #30

Merged
merged 23 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
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
Loading