-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: updated Dockerfile, added compose.yaml
- Loading branch information
Showing
5 changed files
with
139 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,60 @@ | ||
FROM debian:latest | ||
# syntax=docker/dockerfile:1 | ||
|
||
ENV PORT 8080 | ||
# Create a stage for building the application. | ||
ARG GO_VERSION=1.22 | ||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build | ||
WORKDIR /src | ||
|
||
COPY xoracle usr/bin/xoracle | ||
# 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 | ||
|
||
CMD ["/bin/xoracle"] | ||
# This is the architecture you’re building for, which is passed in by the builder. | ||
# Placing it here allows the previous steps to be cached across architectures. | ||
ARG TARGETARCH | ||
|
||
# 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 GOARCH=$TARGETARCH go build -o /bin/server . | ||
|
||
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 \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${UID}" \ | ||
appuser | ||
USER appuser | ||
|
||
# Copy the executable from the "build" stage. | ||
COPY --from=build /bin/server /bin/ | ||
|
||
# Expose the port that the application listens on. | ||
EXPOSE 8080 | ||
|
||
# What the container should run when it is started. | ||
ENTRYPOINT [ "/bin/server" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Comments are provided throughout this file to help you get started. | ||
# If you need more help, visit the Docker compose reference guide at | ||
# https://docs.docker.com/go/compose-spec-reference/ | ||
|
||
# Here the instructions define your application as a service called "server". | ||
# This service is built from the Dockerfile in the current directory. | ||
# You can add other services your application may depend on here, such as a | ||
# database or a cache. For examples, see the Awesome Compose repository: | ||
# https://github.com/docker/awesome-compose | ||
services: | ||
server: | ||
build: | ||
context: . | ||
target: final | ||
ports: | ||
- 8080:8080 | ||
|
||
# The commented out section below is an example of how to define a PostgreSQL | ||
# database that your application can use. `depends_on` tells Docker Compose to | ||
# start the database before your application. The `db-data` volume persists the | ||
# database data between container restarts. The `db-password` secret is used | ||
# to set the database password. You must create `db/password.txt` and add | ||
# a password of your choosing to it before running `docker compose up`. | ||
# depends_on: | ||
# db: | ||
# condition: service_healthy | ||
# db: | ||
# image: postgres | ||
# restart: always | ||
# user: postgres | ||
# secrets: | ||
# - db-password | ||
# volumes: | ||
# - db-data:/var/lib/postgresql/data | ||
# environment: | ||
# - POSTGRES_DB=example | ||
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password | ||
# expose: | ||
# - 5432 | ||
# healthcheck: | ||
# test: [ "CMD", "pg_isready" ] | ||
# interval: 10s | ||
# timeout: 5s | ||
# retries: 5 | ||
# volumes: | ||
# db-data: | ||
# secrets: | ||
# db-password: | ||
# file: db/password.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters