diff --git a/.devcontainer/.dockerignore b/.devcontainer/.dockerignore new file mode 100644 index 0000000..553a2df --- /dev/null +++ b/.devcontainer/.dockerignore @@ -0,0 +1,5 @@ +.dockerignore +devcontainer.json +docker-compose.yml +Dockerfile +README.md \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1e5bde5 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/devcontainers/go:1-1.23-bookworm + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment the next lines to use go get to install anything else you need +# USER vscode +# RUN go get -x +# USER root + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 + +RUN go install -tags 'postgres,mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest && \ + go install github.com/codegangsta/gin@latest \ No newline at end of file diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000..5f96421 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,22 @@ +# Devcontainer README + +The devcontainer uses Docker to create a development environment for the project. You need Visual Studio Code to use this. + +To get started, first follow setting up the environment in the main README, then: + +1. Launch the devcontainer +2. Modifythe .env file by finding and updating the following variables: +```shell +DB_IP=10.50.0.2 +POSTGRES_HOST=10.50.0.3 +``` +3. Migrate the DB by running these commands in the terminal: +```shell +export $(grep -v '^#' .env | xargs) +migrate -path=migrations -database "mysql://$DB_USER:$DB_PASSWORD@tcp($DB_IP)/$DB_NAME" up +migrate -path=postgres_migrations -database "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST?sslmode=disable" up +``` +4. Start the application with live-reloading: +```shell +GIN_PORT=8730 GIT_COMMIT=deadbeef gin --build ./main/ run ./main/main.go +``` \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..533c183 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,86 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/go-postgres +{ + "name": "golang", + "dockerComposeFile": [ + "../dc-db.yml", // Docker Compose will use the first docker-compose file for resolving relative paths.d + "docker-compose.yml" + ], + "service": "dev", + "initializeCommand": "bash ./.devcontainer/postInitCommand.sh", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "remoteUser": "vscode", + "shutdownAction": "stopCompose", + "mounts": [ + "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock,consistency=consistent" + ], + "customizations": { + "vscode": { + "extensions": [ + "golang.go", + "ms-azuretools.vscode-docker", // Docker integration and linting + "shardulm94.trailing-spaces", // Show trailing spaces + "Gruntfuggly.todo-tree", // Highlights TODO comments + "vscode-icons-team.vscode-icons", // Better file extension icons + "github.vscode-pull-request-github", // Github interaction + "redhat.vscode-yaml", // Kubernetes, Drone syntax highlighting + "mtxr.sqltools", // Supports connections to databases, + "mtxr.sqltools-driver-mysql", // MySQL driver for SQLTools + "mtxr.sqltools-driver-pg", // PostgreSQL driver for SQLTools + "IBM.output-colorizer", // Colorize your output/test logs + "github.copilot", // AI code completion, + "yzhang.markdown-all-in-one", // Markdown preview + "eamodio.gitlens" // Better git integration + ], + "settings": { + "files.eol": "\n", + "editor.formatOnSave": true, + "go.buildTags": "", + "go.toolsEnvVars": { + "CGO_ENABLED": "0" + }, + "go.useLanguageServer": true, + "go.testEnvVars": { + "CGO_ENABLED": "1" + }, + "go.testFlags": [ + "-v", + "-race" + ], + "go.testTimeout": "10s", + "go.coverOnSingleTest": true, + "go.coverOnSingleTestFile": true, + "go.coverOnTestPackage": true, + "go.lintTool": "golangci-lint", + "go.lintOnSave": "package", + "[go]": { + "editor.codeActionsOnSave": { + "source.organizeImports": "always" + } + }, + "gopls": { + "usePlaceholders": false, + "staticcheck": true, + "formatting.gofumpt": true + }, + "remote.extensionKind": { + "ms-azuretools.vscode-docker": "workspace" + } + } + } + }, + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/go:1": {}, + } +} +// Features to add to the dev container. More info: https://containers.dev/features. +// "features": {}, +// Configure tool-specific properties. +// "customizations": {}, +// Use 'forwardPorts' to make a list of ports inside the container available locally. +// "forwardPorts": [5432], +// Use 'postCreateCommand' to run commands after the container is created. +// "postCreateCommand": "go version", +// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. +// "remoteUser": "root" \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..3dab084 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,21 @@ +networks: + fpfssnetwork: + driver: bridge + ipam: + config: + - subnet: 10.50.0.0/16 + gateway: 10.50.0.1 + +services: + dev: + build: + context: . + dockerfile: .devcontainer/Dockerfile + networks: + fpfssnetwork: + ipv4_address: 10.50.0.10 + volumes: + - ..:/workspaces:cached + + + command: sleep infinity diff --git a/.devcontainer/postInitCommand.sh b/.devcontainer/postInitCommand.sh new file mode 100755 index 0000000..510c64f --- /dev/null +++ b/.devcontainer/postInitCommand.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# needed so environment variables are available for docker compose +[ ! -f '.devcontainer/.env' ] && cp '.env' '.devcontainer/.env' || true diff --git a/.env.template b/.env.template index 01ba949..b5c7528 100644 --- a/.env.template +++ b/.env.template @@ -52,4 +52,5 @@ DELETED_IMAGES_PATH=./files/deleted-images DELETED_DATA_PACKS_PATH=./files/deleted-games FLASHPOINT_SOURCE_ONLY_MODE=False FLASHPOINT_SOURCE_ONLY_ADMIN_MODE=False -RECOMMENDATION_ENGINE_URL=http://flashpoint-recommendation-engine:8000 \ No newline at end of file +RECOMMENDATION_ENGINE_URL=http://flashpoint-recommendation-engine:8000 +DO_NOT_UNFREEZE_GAME_LIST=[] \ No newline at end of file diff --git a/README.md b/README.md index 263910a..c02dfcc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Not tested on Mac, only on Linux. * MySQL - db for most app data * PostgreSQL - db for metadata edits and updating the master list through the [launcher](https://github.com/FlashpointProject/launcher) * [Validator](https://github.com/FlashpointProject/Curation-Validation-Bot) - validates uploads and post about them on Discord - + Optionally, also run the [archive indexer](https://github.com/Dri0m/recursive-archive-indexer) if you want to upload stuff to what's called Flashfreeze. ## Setting up the environment @@ -36,10 +36,12 @@ Optionally, also run the [archive indexer](https://github.com/Dri0m/recursive-ar Live-reloading can be optionally added by starting the application with [Gin](https://github.com/codegangsta/gin) (`go install github.com/codegangsta/gin@latest`) instead of `go run`: ```shell -GIN_PORT=8730 GIT_COMMIT=deadbeef gin --build ./main/ run ./main/main.go +GIN_PORT=8730 GIT_COMMIT=deadbeef gin --build ./main/ run ./main/main.go ``` The command has to be run from the root directory. `GIN_PORT` is equal to the PORT defined in `.env` file. Now you can visit `http://127.0.0.1:3000` +If you want to use **devcontainer** you can follow the steps as in the readme of the `.devcontainer` folder. + ### Database migrations To add a new migration, add a migration for both up & down to the `migration` and `postgres_migration` directories. The filename of the migration must start with a (version) number higher than the previous migration, for example `0002_primary_platform.down.sql`. @@ -62,11 +64,11 @@ These variables are used in the .env file: * `FLASHPOINT_SERVER_ID` - the server ID you copied from your own private server ##### Discord bot -Create a new Discord bot (you may use the same application created for OAuth2) and click the "Reset token" button to get the private token for the bot. Do not share this token with anyone. +Create a new Discord bot (you may use the same application created for OAuth2). Open the .env file to update the following: -* `AUTH_BOT_TOKEN` - token from the previous step, if you're using a single app +* `AUTH_BOT_TOKEN` - get it from the Discord website using the "Reset Token" button under the "Bot" tab, do not share this * `NOTIFICATION_BOT_TOKEN` - same as the previous one * `NOTIFICATION_CHANNEL_ID` - the ID you copied for the `notifications` channel * `CURATION_FEED_CHANNEL_ID` - the ID you copied for the `curation-feed` channel