Skip to content

Commit

Permalink
feat: add dockerfile (#10)
Browse files Browse the repository at this point in the history
* refactor(main): remove the localhost from the listenandserve function

* build(docker): add a dockerfile to build the container image

* build(makefile): add target commands to the makefile to build and run the container
  • Loading branch information
danvergara authored Nov 3, 2023
1 parent b5e8baf commit ebd72fa
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
LICENSE
README.md
tmp/
.dockerignore
.gitignore
docker-compose.yml
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# syntax=docker/dockerfile:1

# Build the application from source
FROM golang:1.21 AS builder

WORKDIR /app

COPY go.* ./
RUN go mod download

COPY . .

ARG TARGETOS
ARG TARGETARCH

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o morphos .

# Deploy the application binary into a lean image
FROM debian:bookworm-slim AS release

WORKDIR /

COPY --from=builder /app/morphos /bin/morphos

EXPOSE 8080

ENTRYPOINT ["/bin/morphos"]
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ download-htmx:
download-bootstrap:
curl -o static/bootstrap.min.css https://cdn.jsdelivr.net/npm/bootstrap@${BOOTSTRAP_VERSION}/dist/css/bootstrap.min.css
curl -o static/bootstrap.min.js https://cdn.jsdelivr.net/npm/bootstrap@${BOOTSTRAP_VERSION}/dist/js/bootstrap.bundle.min.js

.PHONY: build
## build: Builds the container image
build:
docker build -t morphos .

.PHONY: docker-run
## docker-run: Runs the container
docker-run:
docker run -d -p 8080:8080 morphos

.PHONY: help
## help: Prints this help message
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func main() {
r.Post("/format", handleFileFormat)
r.Get("/modal", handleModal)

http.ListenAndServe("localhost:8080", r)
http.ListenAndServe(":8080", r)
}

func renderError(w http.ResponseWriter, message string, statusCode int) {
Expand Down

0 comments on commit ebd72fa

Please sign in to comment.