Skip to content

Commit

Permalink
Add Docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanfredericks committed Jun 22, 2024
1 parent 3059e21 commit 4dea70a
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.next
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NEXT_PUBLIC_SITE_HOST=
NEXT_PUBLIC_SITE_PORT=
NEXT_PUBLIC_SITE_PROTOCOL=
NEXT_PUBLIC_POGGIT_SEARCH_API_KEY=
NEXT_PUBLIC_CONTACT_EMAIL=
8 changes: 0 additions & 8 deletions .env.local

This file was deleted.

5 changes: 5 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NEXT_PUBLIC_SITE_HOST=localhost
NEXT_PUBLIC_SITE_PORT=3000
NEXT_PUBLIC_SITE_PROTOCOL=http
NEXT_PUBLIC_POGGIT_SEARCH_API_KEY='WvxT4cDyh83sqfHr6pRC8x51SQt2I4TY'
NEXT_PUBLIC_CONTACT_EMAIL=[email protected]
50 changes: 50 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create and publish a Docker image

on:
push:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/out
.idea
node_modules
.env.development
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
Convert PocketMine-MP plugins online.

## Getting Started
```sh
git clone https://github.com/nathanfredericks/pocketmine-tools.git
cd pocketmine-tools
npm install
npm run dev
Before switching environments, remember to delete all existing volumes.
### Development
Don't forget to copy `.env.example` to `.env.development` and fill in missing values before starting the server. Leave `NEXT_PUBLIC_POGGIT_SEARCH_API_KEY` blank.
```shell
docker compose -f compose.dev.yaml up --build
```

### Production
Don't forget to copy `.env.example` to `.env.production` and fill in missing values before starting the server. Leave `NEXT_PUBLIC_POGGIT_SEARCH_API_KEY` blank.
```shell
docker compose -f compose.prod.yaml run update-poggit-search
docker compose -f compose.prod.yaml up --build
```

## Notes
Expand Down
9 changes: 0 additions & 9 deletions components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Tab,
Button,
Nav,
NavDropdown, Badge
} from 'react-bootstrap';
import Link from 'next/link';
import Head from 'next/head';
Expand Down Expand Up @@ -51,14 +50,6 @@ export default function Layout({
<Nav.Link href="/" as={Link} className={isActive(['/']) ? 'active' : ''}>Home</Nav.Link>
<Nav.Link href="/support" as={Link} className={isActive(['/support']) ? 'active' : ''}>Support</Nav.Link>
</Nav>
<Nav className="ms-auto">
<NavDropdown title="Versions">
<NavDropdown.Item href="https://mcpeme.mcpe.fun" target="_blank">mcpe.me</NavDropdown.Item>
<NavDropdown.Item href="https://v1.mcpe.fun" target="_blank">v1 (Old PMT)</NavDropdown.Item>
<NavDropdown.Item href="https://v2.mcpe.fun" target="_blank">v2</NavDropdown.Item>
<NavDropdown.Item href="https://v3.mcpe.fun" target="_blank">v3 <Badge bg="primary">Current</Badge></NavDropdown.Item>
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Container>
</Navbar>
Expand Down
56 changes: 56 additions & 0 deletions compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
services:
pocketmine-tools:
build:
context: .
dockerfile: dev.Dockerfile
restart: unless-stopped
ports:
- 3000:3000
links:
- typesense:typesense
- pmf-decoder:pmf-decoder
volumes:
- .:/app
depends_on:
pmf-decoder:
condition: service_started
typesense:
condition: service_started
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
links:
- typesense:typesense
depends_on:
typesense:
condition: service_healthy
restart: on-failure
volumes:
- ./.env.development:/app/shared/.env.local
typesense:
image: typesense/typesense:26.0
environment:
TYPESENSE_DATA_DIR: /data
TYPESENSE_API_KEY: insecure
volumes:
- typesense:/data
ports:
- 8108:8108
restart: unless-stopped
healthcheck:
test: exit 0
volumes:
typesense:
driver: local
54 changes: 54 additions & 0 deletions compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
services:
pocketmine-tools:
build:
context: .
dockerfile: prod.Dockerfile
restart: unless-stopped
ports:
- 3000:3000
links:
- typesense:typesense
- pmf-decoder:pmf-decoder
depends_on:
pmf-decoder:
condition: service_started
typesense:
condition: service_started
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
links:
- typesense:typesense
depends_on:
typesense:
condition: service_healthy
restart: on-failure
volumes:
- ./.env.production:/app/shared/.env.local
typesense:
image: typesense/typesense:26.0
environment:
TYPESENSE_DATA_DIR: /data
TYPESENSE_API_KEY: insecure
volumes:
- typesense:/data
ports:
- 8108:8108
restart: unless-stopped
healthcheck:
test: exit 0
volumes:
typesense:
driver: local
12 changes: 12 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:20-alpine

WORKDIR /app

COPY package*.json .
RUN npm install

COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

CMD ["npm", "run", "dev"]
12 changes: 12 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
});
const { version } = require('./package.json');
module.exports = withBundleAnalyzer({
async rewrites() {
return [
{
source: '/api/decode-pmf',
destination: 'http://pmf-decoder'
},
{
source: '/api/poggit-search/:path*',
destination: 'http://typesense:8108/:path*'
}
]
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
Expand Down
4 changes: 2 additions & 2 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pocketmine-tools",
"version": "3.0.2",
"version": "3.0.3",
"private": true,
"description": "",
"homepage": "https://pmt.mcpe.fun",
Expand Down
62 changes: 19 additions & 43 deletions pages/pmf-decoder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,80 +28,56 @@ export default class PMFDecoder extends Component {
event.preventDefault();
const { files, beautifyOutput } = this.state;
this.setState({
loading: true,
error: null,
});
if (files) {
const formData = new FormData();
formData.append('fileToUpload', files[0]);
formData.append('plugin', files[0]);
this.setState({
loading: true,
});
// @ts-ignore
const response = await fetch(
`${process.env.NEXT_PUBLIC_PMF_DECODER_PROTOCOL}://${process.env.NEXT_PUBLIC_PMF_DECODER_HOST}:${process.env.NEXT_PUBLIC_PMF_DECODER_PORT}/`,
'/api/decode-pmf',
{
method: 'POST',
body: formData,
},
);
this.setState({
loading: false,
});
if (response.headers.get('Content-Type') !== 'application/json') {
const error: string = await response.text();
switch (error) {
case 'Sorry, your file is too large.':
this.setState({
error: 'Sorry, your .pmf plugin is too large. The maximum size is 5 megabytes.',
errorLink: '/support#pmf-size-error'
});
break;
case 'Sorry, only PMF files are allowed.':
this.setState({
error: 'Sorry, only .pmf plugins are allowed.',
errorLink: '/support#pmf-ext-error'
});
break;
case 'Sorry, there was an error uploading your file.':
this.setState({
error: 'Sorry, there was an error decoding your file.',
errorLink: '/support#pmf-decode-error'
});
break;
}
return this.setState({
loading: false,
this.setState({
error: 'internal server error'
});
}
const json = await response.json();
if (!json.code) {
return this.setState({
loading: false,
error: 'Sorry, there was an error decoding your file.',
errorLink: '/support#pmf-decode-error'
const json = await response.json()
if (!response.ok) {
this.setState({
error: json.message
});
}
const plugin = { ...json };
plugin.code = `<?php ${plugin.code}`;
let { plugin } = json;
plugin = `<?php ${plugin}`;
if (beautifyOutput) {
try {
const prettier = (await import('prettier')).default;
// @ts-ignore
const PhpPlugin = (await import('@prettier/plugin-php/standalone'))
.default;
plugin.code = prettier.format(plugin.code, {
plugin = prettier.format(plugin, {
plugins: [PhpPlugin],
parser: 'php',
});
} catch {
return this.setState({
loading: false,
error:
'Sorry, there was an error beautifying your code. Try turning off beautify output.',
errorLink: '/support#pmf-beautify-error'
error: 'error beautifying code',
});
}
}
this.setState({
loading: false,
});
saveAs(
new Blob([plugin.code]),
new Blob([plugin]),
`${files[0].name.split('.').slice(0, -1).join('.')}.php`,
);
}
Expand Down
Loading

0 comments on commit 4dea70a

Please sign in to comment.