Skip to content

Commit

Permalink
Drastically improve Docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanfredericks committed Aug 1, 2024
1 parent 0e7523d commit 878b096
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NEXT_PUBLIC_SITE_HOST=
NEXT_PUBLIC_SITE_PORT=
NEXT_PUBLIC_SITE_PROTOCOL=
NEXT_PUBLIC_POGGIT_SEARCH_API_KEY=
NEXT_PUBLIC_CONTACT_EMAIL=
TYPESENSE_API_KEY=
TYPESENSE_SEARCH_API_KEY=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/out
.idea
node_modules
.env.development
.env
62 changes: 39 additions & 23 deletions compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
services:
pocketmine-tools:
image: ghcr.io/nathanfredericks/pocketmine-tools:main
environment:
- NEXT_PUBLIC_SITE_HOST=
- NEXT_PUBLIC_SITE_PORT=
- NEXT_PUBLIC_SITE_PROTOCOL=
- NEXT_PUBLIC_POGGIT_SEARCH_API_KEY=
- NEXT_PUBLIC_CONTACT_EMAIL=
build:
context: .
dockerfile: prod.Dockerfile
env_file:
- .env
restart: unless-stopped
ports:
- 3000:3000
Expand All @@ -17,40 +15,58 @@ services:
pmf-decoder:
condition: service_started
typesense:
condition: service_started
condition: service_healthy
generate-typesense-api-key:
condition: service_completed_successfully
update-poggit-search:
condition: service_completed_successfully

pmf-decoder:
image: ghcr.io/nathanfredericks/pmf-decoder:main
restart: unless-stopped

update-poggit-search:
image: ghcr.io/nathanfredericks/update-poggit-search:main
environment:
TYPESENSE_HOST: typesense
TYPESENSE_PORT: 8108
TYPESENSE_PROTOCOL: http
TYPESENSE_API_KEY: insecure
POGGIT_PROTOCOL: https
POGGIT_HOST: poggit.pmmp.io
POGGIT_PORT: 443
env_file:
- .env
links:
- typesense:typesense
depends_on:
typesense:
condition: service_healthy
restart: on-failure

typesense:
image: typesense/typesense:26.0
build:
context: docker
dockerfile: typesense.Dockerfile
container_name: typesense
env_file:
- .env
environment:
TYPESENSE_DATA_DIR: /data
TYPESENSE_API_KEY: insecure
volumes:
- typesense:/data
ports:
- 8108:8108
restart: unless-stopped
healthcheck:
test: exit 0
test: curl http://typesense:8108/health || exit 1
interval: 0s

generate-typesense-api-key:
build:
context: docker
dockerfile: curl.Dockerfile
container_name: generate-typesense-api-key
env_file:
- .env
volumes:
- ./docker/scripts/generate-typesense-api-key.sh:/app/generate-typesense-api-key.sh
command: sh /app/generate-typesense-api-key.sh
links:
- typesense:typesense
depends_on:
typesense:
condition: service_healthy

volumes:
typesense:
driver: local
typesense:
4 changes: 4 additions & 0 deletions docker/curl.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine/curl:8.9.0

RUN apk update
RUN apk add jq
20 changes: 20 additions & 0 deletions docker/scripts/generate-typesense-api-key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
keys=$(curl -s "http://typesense:8108/keys" \
-H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY")

keys_length=$(echo "$keys" | jq ".keys | length")

if [ "$keys_length" -gt 1 ]; then
exit 0
else
curl "http://typesense:8108/keys" \
-f \
-H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "Search-only plugins key.",
"actions": ["documents:search"],
"collections": ["plugins"],
"value": "'"${TYPESENSE_SEARCH_API_KEY}"'"
}'
fi
4 changes: 4 additions & 0 deletions docker/typesense.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM typesense/typesense:26.0

RUN apt-get update
RUN apt-get install -y curl
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ module.exports = withBundleAnalyzer({
publicRuntimeConfig: {
version,
},
env: {
NEXT_PUBLIC_TYPESENSE_API_KEY: process.env.TYPESENSE_SEARCH_API_KEY
}
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pages/poggit-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class PoggitSearch extends Component {
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
server: {
// @ts-ignore
apiKey: process.env.NEXT_PUBLIC_POGGIT_SEARCH_API_KEY,
apiKey: process.env.NEXT_PUBLIC_TYPESENSE_API_KEY,
nodes: [
{
// @ts-ignore
Expand Down
4 changes: 3 additions & 1 deletion prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

CMD npm run build && npm start
RUN npm run build

CMD npm start

0 comments on commit 878b096

Please sign in to comment.