diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..482621a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.zig-cache/ +zig-out/ + diff --git a/.gitignore b/.gitignore index 5485280..000a189 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ zig-out/ zig-cache/ +data/ *.core .jetzig .zig-cache/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ddb96fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM alpine:latest AS build +RUN apk add jq curl tar xz git vim +RUN curl --output /zig.tar.xz "$(curl -s 'https://ziglang.org/download/index.json' | jq -r '.master."x86_64-linux".tarball')" + +RUN mkdir /zig +WORKDIR /zig +RUN tar -xf /zig.tar.xz + +RUN mkdir /app +COPY . /app/ +WORKDIR /app/ +RUN /zig/zig-*/zig build -Denvironment=production install + +run mkdir /jetzig +WORKDIR /jetzig +RUN git clone https://github.com/jetzig-framework/jetzig . +WORKDIR ./cli +RUN /zig/zig-*/zig build install + +FROM alpine:latest + +# copy zig over +RUN mkdir /.zig +COPY --from=build /zig/zig-*/ /.zig +ENV PATH="/.zig:$PATH" + +# copy jetzig over +COPY --from=build /jetzig/cli/zig-out/bin/jetzig /usr/local/bin/jetzig + +RUN mkdir -p /app/public +COPY --from=build /app /app +COPY --from=build /app/zig-out/bin/yuzucchiidotxyz /app/server +WORKDIR /app/ +EXPOSE 8080 +ENTRYPOINT ["./server"] +CMD ["/app/server", "--bind", "0.0.0.0", "--port", "8080"] diff --git a/build.zig b/build.zig index 349fa7b..30b027b 100644 --- a/build.zig +++ b/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const exe = b.addExecutable(.{ - .name = "yuzucchii.xyz", + .name = "yuzucchiidotxyz", .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, diff --git a/compose.yml b/compose.yml index 8c7cd31..1f755e3 100644 --- a/compose.yml +++ b/compose.yml @@ -1,8 +1,31 @@ services: + server: + env_file: ".env" + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + restart: unless-stopped + depends_on: + - postgres + networks: + - postgres-network + postgres: image: postgres:16 + env_file: ".env" environment: POSTGRES_USER: ${JETQUERY_USERNAME} POSTGRES_PASSWORD: ${JETQUERY_PASSWORD} ports: - - 5432:5432 + - "5431:5432" + volumes: + - ./data/:/var/lib/postgresql/data/ + networks: + - postgres-network + +networks: + postgres-network: + driver: bridge + diff --git a/config/database.zig b/config/database.zig index ab4ddc2..46fae6b 100644 --- a/config/database.zig +++ b/config/database.zig @@ -7,5 +7,6 @@ pub const database = .{ }, .production = .{ .adapter = .postgresql, + .hostname = "postgres" }, };