mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-19 03:26:46 +02:00
Merge pull request #100 from lsmoura/sergio/simple-docker
Improve docker images by using alpine, simplifying Dockerfiles, and improving the docker-compose example
This commit is contained in:
commit
4d0b45d975
4
Makefile
4
Makefile
@ -25,11 +25,11 @@ release:
|
||||
git push && git push --tags
|
||||
|
||||
build-static:
|
||||
ssh server "cd ~/code/hishtory/; git pull; docker build -t gcr.io/dworken-k8s/hishtory-static -f backend/web/caddy/Dockerfile ."
|
||||
ssh server "cd ~/code/hishtory/; git pull; docker build --build-arg GOARCH=amd64 --tag gcr.io/dworken-k8s/hishtory-static --file backend/web/caddy/Dockerfile ."
|
||||
|
||||
build-api:
|
||||
rm hishtory server || true
|
||||
docker build -t gcr.io/dworken-k8s/hishtory-api -f backend/server/Dockerfile .
|
||||
docker build --build-arg GOARCH=amd64 --tag gcr.io/dworken-k8s/hishtory-api --file backend/server/Dockerfile .
|
||||
|
||||
deploy-static: build-static
|
||||
ssh server "docker push gcr.io/dworken-k8s/hishtory-static"
|
||||
|
@ -1,10 +1,14 @@
|
||||
FROM golang:1.18 AS builder
|
||||
COPY go.mod ./
|
||||
COPY go.sum ./
|
||||
RUN unset GOPATH; go mod download
|
||||
COPY . ./
|
||||
RUN unset GOPATH; GOARCH=amd64 go build -o /server -ldflags "-X main.ReleaseVersion=v0.`cat VERSION`" backend/server/server.go
|
||||
FROM golang:1.18-alpine3.17 AS builder
|
||||
|
||||
FROM golang:1.18
|
||||
WORKDIR /app
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . ./
|
||||
ARG GOARCH
|
||||
RUN apk add --update --no-cache --virtual .build-deps build-base && \
|
||||
GOARCH=${GOARCH} go build -o /server -ldflags "-X main.ReleaseVersion=v0.`cat VERSION`" backend/server/server.go && \
|
||||
apk del .build-deps
|
||||
|
||||
FROM alpine:3.17
|
||||
COPY --from=builder /server /server
|
||||
CMD ["/server"]
|
||||
|
@ -5,6 +5,7 @@
|
||||
# 4. Point your hiSHtory client at the server by putting `export HISHTORY_SERVER=http://1.2.3.4` in your shellrc
|
||||
# 5. Run `hishtory init` to initialize hiSHtory with the local server
|
||||
# 6. [Optional, but recommended] Add a TLS proxy to enable https
|
||||
version: "3.8"
|
||||
networks:
|
||||
hishtory:
|
||||
driver: bridge
|
||||
@ -19,17 +20,28 @@ services:
|
||||
POSTGRES_DB: hishtory
|
||||
PGDATA: /var/lib/postgresql/data/pgdata
|
||||
volumes:
|
||||
- ./postgres-data:/var/lib/postgresql/data
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: pg_isready -U postgres
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
hishtory:
|
||||
depends_on:
|
||||
- postgres
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- hishtory
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: ./backend/server/native-arch-Dockerfile
|
||||
dockerfile: ./backend/server/Dockerfile
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
delay: 3s
|
||||
environment:
|
||||
HISHTORY_POSTGRES_DB: postgresql://postgres:TODO_YOUR_POSTGRES_PASSWORD_HERE@postgres:5432/hishtory?sslmode=disable
|
||||
ports:
|
||||
- 80:8080
|
||||
volumes:
|
||||
postgres-data:
|
||||
|
@ -1,17 +0,0 @@
|
||||
# A fork of Dockerfile that doesn't hard code GOARCH and that uses wait-for to wait
|
||||
# until the postgres server is up. Meant to be used in the docker-compose file for self hosting.
|
||||
|
||||
FROM golang:1.18 AS builder
|
||||
COPY go.mod ./
|
||||
COPY go.sum ./
|
||||
RUN unset GOPATH; go mod download
|
||||
COPY . ./
|
||||
RUN unset GOPATH; go build -o /server -ldflags "-X main.ReleaseVersion=v0.`cat VERSION`" backend/server/server.go
|
||||
|
||||
FROM golang:1.18
|
||||
RUN apt-get update && apt-get install -y netcat
|
||||
# Downlaod wait-for from a specific commit hash. This ensures that the owner of wait-for isn't in our TCB (though Github still is)
|
||||
RUN curl https://raw.githubusercontent.com/eficode/wait-for/59bec22851ba83e9cc735a67a7d961f8aae2cd85/wait-for > /wait-for
|
||||
RUN chmod +x /wait-for
|
||||
COPY --from=builder /server /server
|
||||
CMD ["/wait-for", "postgres:5432", "--", "/server"]
|
Loading…
x
Reference in New Issue
Block a user