ID:FCLD-228;DONE:7;HOURS:7; system file gen test in builder

This commit is contained in:
Sameer Dev 2024-04-23 17:34:36 +05:30
parent 832f59f612
commit 4635bd4d77
5 changed files with 80 additions and 0 deletions

43
Dockerfile Normal file
View File

@ -0,0 +1,43 @@
### SYSTEM GENERATED FILE, MAKE CHANGES AS NEEDED ###
# Use a specific version as the base image for the builder stage
FROM golang:1.21-alpine AS builder
# Set /app as the working directory in the builder stage
WORKDIR /app
### UNCOMMENT AS NEEDED ###
# Copy go.mod and go.sum files into the builder stage
# This allows the dependencies to be installed before copying the rest of the application code
COPY go.sum ./
COPY go.mod ./
### DEFAULT BOOTSTRAP BUILD CODE, RUN LOCALLY TO GENERATE go.mod ###
# If go.mod exists and not empty, install the listed packages
# If it doesn't exist or is empty, print a message and skip the installation
RUN if [ -s go.mod ]; then \
go mod download; \
else \
echo "No go.mod found, continuing with default settings"; \
go mod init app; \
fi
# Copy the rest of the application code into the builder stage
COPY . /app
# Build the application
RUN go build -v -o app .
# Start a new stage with a distroless image for smaller image size and improved security
FROM gcr.io/distroless/static-debian11
# Copy the /app directory from the builder stage into the current stage
# This includes the application code and the installed packages
COPY --from=builder /app /app
# Set /app as the working directory in the current stage
WORKDIR /app
# Set the command to run when the container starts
# This will start the application
CMD [ "./app" ]

15
fc.toml Normal file
View File

@ -0,0 +1,15 @@
app = "golang-dockerfile-app-sample"
region = "asia-south1"
handler = ""
[build]
dockerfile = "Dockerfile"
ignorefile = ".gitignore"
[build.args]
foo = "bar"
[env]
FOO = "BAR"
[http_service]
internal_port = 3000

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module golang-buildpack-app-sample
go 1.21.5

0
go.sum Normal file
View File

19
main.go Normal file
View File

@ -0,0 +1,19 @@
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
}
func main() {
// Register the handler function to handle requests to "/"
http.HandleFunc("/", handler)
// Start the HTTP server on port 3000
fmt.Println("Example app listening on port 3000!")
http.ListenAndServe(":3000", nil)
}