Skip to content

Commit

Permalink
Create Dockerfile
Browse files Browse the repository at this point in the history
This Dockerfile sets up a multi-stage build for a web application:

    The first stage compiles the Golang backend code and creates a 'main' binary.
    The second stage handles frontend asset compilation, specifically converting SCSS to CSS using SASS.
    Finally, it combines the Golang binary and compiled CSS into a final image, ready to run the web application on port 8080.

Signed-off-by: pushpit kamboj <[email protected]>
  • Loading branch information
pushpitkamboj authored Nov 16, 2023
1 parent ca372a4 commit 7082458
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Stage 1: Build Golang backend
FROM golang:latest AS backend

WORKDIR /app

# Copy and build the Golang application
COPY . .
RUN go build -o main ./*.go

# Stage 2: Build frontend assets (SCSS to CSS)
FROM node:latest AS frontend

WORKDIR /app

# Copy only the necessary frontend files (SCSS, etc.)
COPY . .

# Install dependencies and compile SCSS to CSS
RUN npm install -g sass # Install SASS globally
RUN sass input.scss output.css # Replace with your SCSS compilation command

# Stage 3: Final stage
FROM golang:latest

WORKDIR /app

# Copy the built Golang binary from the first stage
COPY --from=backend /app/main .

# Copy the compiled CSS files from the second stage
COPY --from=frontend /app/output.css ./public/output.css

# Expose the port your web application runs on (if applicable)
EXPOSE 8080

# Set the default command to start the web server
CMD ["./main"]


#if you are more familiar with CCS for frontend development than SCSS use these instruction
# Install dependencies and compile SCSS to CSS
RUN npm install -g sass # Install SASS globally (if using Node.js)
RUN sass input.scss output.css # Replace with your SCSS compilation command

0 comments on commit 7082458

Please sign in to comment.