Skip to content

Commit

Permalink
chore(docker): support run and deploy to vercel in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ngshiheng committed Feb 3, 2024
1 parent ad1271b commit 180840f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ crawl: ## crawl data and save it into /data directory.
@rm -rf michelin.db
@go run cmd/mym/mym.go

.PHONY: docker-build
docker-build: ## build docker image.
$(DOCKER) build -t $(NAME) . -f docker/Dockerfile

.PHONY: docker-run
docker-run: ## run local development server in docker.
@$(DOCKER) stop $(NAME) || true && $(DOCKER) rm $(NAME) || true
$(DOCKER) run -e VERCEL_TOKEN=$(VERCEL_TOKEN) --name $(NAME) $(NAME)


##@ Utility
.PHONY: sqlitetocsv
sqlitetocsv: ## convert data from sqlite3 to csv.
@if [ -z $(SQLITE) ]; then echo "SQLite3 could not be found. See https://www.sqlite.org/download.html"; exit 2; fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Alternatively, you can install this directly via `go install`:

```sh
go install github.com/ngshiheng/michelin-my-maps/v2/cmd/mym
rm michelin_my_maps.db
rm michelin.db
mym -log debug
```

Expand Down
1 change: 0 additions & 1 deletion docker/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
**/*.png
cache/
data/
docs/
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.21-alpine AS go-builder
WORKDIR $GOPATH/src/github.com/ngshiheng/michelin-my-maps
COPY . .
RUN go build -o /bin/mym ./cmd/mym

FROM datasetteproject/datasette
RUN datasette install datasette-publish-vercel

COPY --from=go-builder /bin/mym /bin/mym

ARG VERCEL_TOKEN
ENV VERCEL_TOKEN=${VERCEL_TOKEN}
RUN apt-get update -yq
RUN apt-get -yq install curl gnupg ca-certificates
RUN curl -L https://deb.nodesource.com/setup_18.x | bash
RUN apt-get install -yq nodejs
RUN npm i -g vercel

COPY . .
CMD ["./docker/docker-entrypoint.sh"]
43 changes: 43 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e

main() {
check
run_mym
publish_to_vercel
}

check() {
echo "Checking..."
if [ -z "$VERCEL_TOKEN" ]; then
echo "Error: VERCEL_TOKEN is not set. Please set it before running this script."
exit 1
fi

if ! command -v vercel &>/dev/null; then
echo "Error: vercel is not installed. Please install it before running this script."
exit 1
fi

if ! command -v datasette &>/dev/null; then
echo "Error: datasette is not installed. Please install it before running this script."
exit 1
fi
}

run_mym() {
echo "Running mym..."
mym
if [ ! -f michelin.db ]; then
echo "Error: michelin.db does not exist. Exiting..."
exit 1
fi
}

publish_to_vercel() {
echo "Publishing datasette to Vercel..."
datasette publish vercel michelin.db --project=michelin-my-maps --install=datasette-cluster-map --token="$VERCEL_TOKEN"
}

main "$@"

0 comments on commit 180840f

Please sign in to comment.