From c3940933bb3bfa8dd9ec63bb7052f1c6965e06f8 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Tue, 4 Apr 2023 15:17:55 +0200 Subject: [PATCH] Add Dockerfile --- .dockerignore | 7 +++++++ Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ Makefile | 9 ++++++++- go.mod | 2 +- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe9edce --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules/ +gist.db +.idea/ +.DS_Store +/**/.DS_Store +public/assets/* +public/manifest.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a1fb283 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM alpine:3.17 + +# Install required dependencies +RUN apk update && \ + apk add --no-cache \ + openssl \ + openssh \ + curl \ + wget \ + git \ + gnupg \ + make \ + xz \ + gcc \ + musl-dev \ + libstdc++ + +# Install Golang +COPY --from=golang:1.19-alpine /usr/local/go/ /usr/local/go/ +ENV PATH="/usr/local/go/bin:${PATH}" + +# Install Node.js +COPY --from=node:16-alpine /usr/local/ /usr/local/ +ENV NODE_PATH="/usr/local/lib/node_modules" +ENV PATH="/usr/local/bin:${PATH}" + +# Set the working directory +WORKDIR /opengist + +# Copy all source files +COPY . . + +# Build the application +RUN make + +# Expose the port for the webserver +EXPOSE 6157 + +# Mount the .opengist volume +VOLUME /root/.opengist + +# Run the webserver +CMD ["./opengist"] diff --git a/Makefile b/Makefile index b061687..6017e81 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all install_deps build_frontend build_backend clean +.PHONY: all install_deps build_frontend build_backend build_docker clean clean_docker # Specify the name of your Go binary output BINARY_NAME := opengist @@ -19,8 +19,15 @@ build_backend: @echo "Building Opengist binary..." go build -o $(BINARY_NAME) opengist.go +build_docker: + @echo "Building Docker image..." + docker build -t opengist . + clean: @echo "Cleaning up build artifacts..." @rm -f $(BINARY_NAME) public/manifest.json @rm -rf node_modules public/assets +clean_docker: + @echo "Cleaning up Docker image..." + @docker rmi opengist \ No newline at end of file diff --git a/go.mod b/go.mod index 25a1781..4e101bf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module opengist -go 1.18 +go 1.19 require ( github.com/go-playground/validator/v10 v10.11.0