Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat devcontainer #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .devcontainer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dockerignore
devcontainer.json
docker-compose.yml
Dockerfile
README.md
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <your-package-list-here>

# [Optional] Uncomment the next lines to use go get to install anything else you need
# USER vscode
# RUN go get -x <your-dependency-or-tool>
# 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 <your-package-here>" 2>&1

RUN go install -tags 'postgres,mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest && \
go install github.com/codegangsta/gin@latest
22 changes: 22 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -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
```
86 changes: 86 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .devcontainer/postInitCommand.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
RECOMMENDATION_ENGINE_URL=http://flashpoint-recommendation-engine:8000
DO_NOT_UNFREEZE_GAME_LIST=[]
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.

Expand All @@ -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
Expand Down