Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
Update somes thing
Browse files Browse the repository at this point in the history
  • Loading branch information
exatombe committed Nov 30, 2023
1 parent d7af299 commit 7d771f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.exe
48 changes: 18 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,38 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/
ARG GO_VERSION=1.21.4

################################################################################
# Create a stage for building the application.
ARG GO_VERSION=1.21.4
FROM golang:${GO_VERSION} AS build
WORKDIR /src

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into
# the container.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x

# Build the application.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage a bind mount to the current directory to avoid having to copy the
# source code into the container.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
CGO_ENABLED=0 go build -o /bin/server .

# Copy the 'public' folder from the local directory into the container.
FROM build AS copy-public
WORKDIR /app

COPY public /app/public

################################################################################
# Create a new stage for running the application that contains the minimal
# runtime dependencies for the application. This often uses a different base
# image from the build stage where the necessary files are copied from the build
# stage.
#
# The example below uses the alpine image as the foundation for running the app.
# By specifying the "latest" tag, it will also use whatever happens to be the
# most recent version of that image when you build your Dockerfile. If
# reproducability is important, consider using a versioned tag
# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff).
# runtime dependencies for the application.
FROM alpine:latest AS final

# Install any runtime dependencies that are needed to run your application.
# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds.
RUN --mount=type=cache,target=/var/cache/apk \
apk --update add \
ca-certificates \
tzdata \
&& \
update-ca-certificates

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
RUN adduser \
--disabled-password \
Expand All @@ -62,11 +44,17 @@ RUN adduser \
appuser
USER appuser

# Copy the executable from the "build" stage.
COPY --from=build /bin/server /bin/
COPY --from=build /src/public /bin/public
# Create a directory for the application and set it as the working directory.
WORKDIR /app

# Copy the executable from the "build" stage into the current directory.
COPY --from=build /bin/server .

# Copy the 'public' folder from the "copy-public" stage into the current directory.
COPY --from=copy-public /app/public ./public

# Expose the port that the application listens on.
EXPOSE 5454

# What the container should run when it is started.
ENTRYPOINT [ "/bin/server" ]
ENTRYPOINT [ "/app/server" ]
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
routes.NotFoundHandler(w, r, fsys)
return
}
routes.AnimeHandler(w, r,id, fsys)
routes.AnimeHandler(w, r, id, fsys)
}))

router.Handle("/anime/{id}/episode/{episode}", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -69,7 +69,7 @@ func main() {
routes.NotFoundHandler(w, r, fsys)
return
}
routes.EpisodeHandler(w, r,id, episode, fsys)
routes.EpisodeHandler(w, r, id, episode, fsys)
}))

router.HandleFunc("/history", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -81,5 +81,8 @@ func main() {
Handler: router,
}
log.Println("Listening on port " + port)
server.ListenAndServe()
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 7d771f0

Please sign in to comment.