containerize
This commit is contained in:
parent
825f630108
commit
d280bf77d1
34
.dockerignore
Normal file
34
.dockerignore
Normal file
@ -0,0 +1,34 @@
|
||||
# Include any files or directories that you don't want to be copied to your
|
||||
# container here (e.g., local build artifacts, temporary files, etc.).
|
||||
#
|
||||
# For more help, visit the .dockerignore file reference guide at
|
||||
# https://docs.docker.com/go/build-context-dockerignore/
|
||||
|
||||
**/.DS_Store
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose.y*ml
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
db
|
||||
omada
|
64
Dockerfile
Normal file
64
Dockerfile
Normal file
@ -0,0 +1,64 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
ARG PROJECT=examples/groups.fiatjaf.com
|
||||
|
||||
# Create a stage for building the application.
|
||||
ARG GO_VERSION=1.23.4
|
||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
|
||||
WORKDIR /src
|
||||
|
||||
ARG PROJECT
|
||||
# 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.mod,target=go.mod \
|
||||
go mod download -x
|
||||
|
||||
# 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=1 GOARCH=$TARGETARCH go build -o /bin/server ./${PROJECT}
|
||||
|
||||
################################################################################
|
||||
# Create a new stage for running the application that contains the minimal
|
||||
# runtime dependencies for the application.
|
||||
FROM debian:bookworm-slim AS final
|
||||
|
||||
RUN --mount=type=cache,target=/var/cache/apt \
|
||||
apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
tzdata \
|
||||
libc6 \
|
||||
&& \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 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 --from=build /bin/server /app/
|
||||
|
||||
RUN chmod ugo+x /app/server
|
||||
|
||||
EXPOSE 4200
|
||||
|
||||
CMD [ "/app/server" ]
|
22
README.Docker.md
Normal file
22
README.Docker.md
Normal file
@ -0,0 +1,22 @@
|
||||
### Building and running your application
|
||||
|
||||
When you're ready, start your application by running:
|
||||
`docker compose up --build`.
|
||||
|
||||
Your application will be available at http://localhost:4200.
|
||||
|
||||
### Deploying your application to the cloud
|
||||
|
||||
First, build your image, e.g.: `docker build -t myapp .`.
|
||||
If your cloud uses a different CPU architecture than your development
|
||||
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
|
||||
you'll want to build the image for that platform, e.g.:
|
||||
`docker build --platform=linux/amd64 -t myapp .`.
|
||||
|
||||
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.
|
||||
|
||||
Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
|
||||
docs for more detail on building and pushing.
|
||||
|
||||
### References
|
||||
* [Docker's Go guide](https://docs.docker.com/language/golang/)
|
21
compose.yaml
Normal file
21
compose.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
services:
|
||||
relay29:
|
||||
build:
|
||||
context: .
|
||||
target: final
|
||||
args:
|
||||
- PROJECT=examples/groups.fiatjaf.com # OPTIONAL
|
||||
volumes:
|
||||
- ./db:/db
|
||||
environment:
|
||||
- DOMAIN=groups.example.com
|
||||
- RELAY_NAME=Groups Relay
|
||||
- RELAY_PRIVKEY=XXXXX
|
||||
- DATABASE_PATH=/db
|
||||
- PORT=4200
|
||||
# OPTIONAL
|
||||
- RELAY_DESCRIPTION=Groups Relay
|
||||
# - RELAY_CONTACT=contact@example.com
|
||||
# - RELAY_ICON=https://example.com/icon.png
|
||||
ports:
|
||||
- 4200:4200
|
Loading…
x
Reference in New Issue
Block a user