Skip to content
Merged
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
18 changes: 11 additions & 7 deletions docker_config_generator/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ services:
description: Spring Boot based web application with Maven
golang:
name: Golang
description: Golang based web application
description: Golang based application

templates:
sinatra:
Expand Down Expand Up @@ -144,18 +144,22 @@ templates:
golang:
name: golang.Dockerfile
variables:
NAME:
BINARY_NAME:
type: string
description: Name for the golang module
description: Name for the golang application (No Space)
default: app
CGO_ENABLED:
type: string
description: CGO_ENABLED for golang
default: "0"
BUILD_COMMAND:
type: string
description: Build command for golang
description: Build command for golang app
default: go build -o app .
PORT:
START_COMMAND:
type: string
description: Exposed Port [Ignore if not required]
default: 80
description: Start command for golang app
default: ./app
reactjs:
name: frontend.Dockerfile
variables:
Expand Down
65 changes: 40 additions & 25 deletions docker_config_generator/templates/golang.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
FROM golang:1.20-alpine AS builder
FROM golang:1.21.1-bullseye AS builder

# -- Args
# Build Args
ARG BUILD_COMMAND="go build -o app ."
ARG NAME="app"
ARG PORT="80"
ARG BINARY_NAME="app"
ARG CGO_ENABLED="0"
# Env setup
ENV CGO_ENABLED=${CGO_ENABLED}

# -- build env setup --
ENV CGO_ENABLED=0
RUN apk update && apk --no-cache upgrade
RUN apk --no-cache add ca-certificates git
# Setup workdir
WORKDIR /build

# -- Fetch dependencies --
COPY go.mod go.sum ./
# Copy source code
COPY . .

# Copy AptFile [optional]
RUN test -f AptFile && apt update -yqq && xargs -a AptFile apt install -yqq || true

# Copy SetupCommand [optional]
RUN test -f SetupCommand && while read -r cmd; do eval "$cmd"; done < SetupCommand || true

# Fetch dependencies
RUN go mod download

COPY . .
RUN ${BUILD_COMMAND}

# -- Runner stage --
FROM alpine:latest AS runner
# Runner stage
FROM golang:1.21.1-bullseye AS runner

# -- env setup --
ARG NAME="app"
RUN apk --no-cache upgrade
RUN mkdir /user \
&& adduser -D user --shell /usr/sbin/nologin \
&& chown -R user:user /user
# Build Args
ARG BINARY_NAME="app"
ARG START_COMMAND="./app"

# Setup workdir
WORKDIR /user

COPY --from=builder /build/${NAME} .
EXPOSE ${PORT}
ENV PORT ${PORT}
# Copy binary
COPY --from=builder /build/${BINARY_NAME} .

# Install OS dependencies

# Copy AptFile [optional]
COPY AptFile* ./
RUN test -f AptFile && apt update -yqq && xargs -a AptFile apt install -yqq || true

# Copy SetupCommand [optional]
COPY SetupCommand* ./
RUN test -f SetupCommand && while read -r cmd; do eval "$cmd"; done < SetupCommand || true

RUN echo "/user/${NAME}" > /user/entrypoint.sh
# Create entrypoint
RUN echo ${START_COMMAND} > /user/entrypoint.sh
RUN chmod +x /user/entrypoint.sh
USER user

ENTRYPOINT ["sh", "-c", "/user/entrypoint.sh"]
# Setup Entrypoint
ENTRYPOINT ["sh", "-c", "/user/entrypoint.sh"]