mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +02:00
docker improvements:
* use alpine for small docker images * use docker compose to wait for the database to be ready * use a single Dockerfile with parameters to determine the correct GOARCH * update makefile to account for the new GOARCH parameter on the Dockerfile * remove native-arch-Dockerfile
This commit is contained in:
parent
aa3c7fc41a
commit
a3e6d5a940
4
Makefile
4
Makefile
@ -25,11 +25,11 @@ release:
|
|||||||
git push && git push --tags
|
git push && git push --tags
|
||||||
|
|
||||||
build-static:
|
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:
|
build-api:
|
||||||
rm hishtory server || true
|
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
|
deploy-static: build-static
|
||||||
ssh server "docker push gcr.io/dworken-k8s/hishtory-static"
|
ssh server "docker push gcr.io/dworken-k8s/hishtory-static"
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
FROM golang:1.18 AS builder
|
FROM golang:1.18-alpine3.17 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
|
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
|
COPY --from=builder /server /server
|
||||||
CMD ["/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
|
# 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
|
# 5. Run `hishtory init` to initialize hiSHtory with the local server
|
||||||
# 6. [Optional, but recommended] Add a TLS proxy to enable https
|
# 6. [Optional, but recommended] Add a TLS proxy to enable https
|
||||||
|
version: "3.8"
|
||||||
networks:
|
networks:
|
||||||
hishtory:
|
hishtory:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
@ -19,17 +20,28 @@ services:
|
|||||||
POSTGRES_DB: hishtory
|
POSTGRES_DB: hishtory
|
||||||
PGDATA: /var/lib/postgresql/data/pgdata
|
PGDATA: /var/lib/postgresql/data/pgdata
|
||||||
volumes:
|
volumes:
|
||||||
- ./postgres-data:/var/lib/postgresql/data
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: pg_isready -U postgres
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
hishtory:
|
hishtory:
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- hishtory
|
- hishtory
|
||||||
build:
|
build:
|
||||||
context: ../../
|
context: ../../
|
||||||
dockerfile: ./backend/server/native-arch-Dockerfile
|
dockerfile: ./backend/server/Dockerfile
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
deploy:
|
||||||
|
restart_policy:
|
||||||
|
condition: on-failure
|
||||||
|
delay: 3s
|
||||||
environment:
|
environment:
|
||||||
HISHTORY_POSTGRES_DB: postgresql://postgres:TODO_YOUR_POSTGRES_PASSWORD_HERE@postgres:5432/hishtory?sslmode=disable
|
HISHTORY_POSTGRES_DB: postgresql://postgres:TODO_YOUR_POSTGRES_PASSWORD_HERE@postgres:5432/hishtory?sslmode=disable
|
||||||
ports:
|
ports:
|
||||||
- 80:8080
|
- 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