Skip to content

Commit

Permalink
release the source code
Browse files Browse the repository at this point in the history
  • Loading branch information
alihardan committed Jun 14, 2024
0 parents commit c352edc
Show file tree
Hide file tree
Showing 100 changed files with 13,491 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.git
.idea
.env
node_modules
vendor
storage/framework/cache/**
storage/framework/sessions/**
storage/framework/views/**
public/hot/
public/storage/
storage/*.key
vendor/
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
Dockerfile
docker-compose.yml
docker-compose.yaml
**.git
.idea
**.gitignore
**.gitattributes
**.sass-cache
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
70 changes: 70 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"

# OPG
TELEGRAM_TOKEN="api-telegram-token"
OWNER_TG_ID=''
TELEGRAM_API=
TELEGRAM_HASH=
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: ["main"]

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# build-args: |
# BACKUP_TOKEN=${{ secrets.BACKUP_TOKEN }}
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM webdevops/php-nginx:8.3
ENV WEB_DOCUMENT_ROOT=/app/public

# Use the default production configuration
# RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN apt-get --allow-insecure-repositories update && apt-get install -y mariadb-client
RUN apt clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY . .

# RUN chown -R www-data:www-data ./

# Change current user to www
# USER www-data

RUN composer install --optimize-autoloader --no-dev
# RUN php artisan config:cache
# RUN php artisan route:cache
# RUN php artisan optimize
RUN chown -R application:application .

# Expose port 9000 and start php-fpm server
# EXPOSE 9000
# CMD ["php-fpm"]

RUN rm -rf /app/storage/app/public
RUN ln -s /opgactions/opg-backups/public /app/storage/app/public
RUN php artisan storage:link
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Deploy

- apt-get install certbot -y && certbot certonly --standalone --agree-tos --register-unsafely-without-email --key-type rsa -d backend.oldpersiangames.org && certbot renew --dry-run
- get docker-compose.yml and put in /opt/opgbackend/docker-compose.yml (remove build at app and uncomment image at app)
- copy .env file kenare docker-compose.yml, set mysql host to "db", and set user pass, add APP_KEY, also:
SANCTUM_STATEFUL_DOMAINS=dash.oldpersiangames.org
SESSION_DOMAIN=.oldpersiangames.org
FRONTEND_URL=https://dash.oldpersiangames.org
also TELEGRAM_TOKEN=bot_token and OWNER_TG_ID=yourid
also TELEGRAM_API and TELEGRAM_HASH for your python bot
also OPG_KEY_HASH
- docker compose pull && docker compose up --build -d
- git clone https://${BACKUP_TOKEN}@github.com/oldpersiangames/opg-backups /opgactions/opg-backups && cd /opgactions/opg-backups && git config user.email [email protected] && git config user.name alihardan
- docker compose exec app bash -c "mysql -h db -u opg -p123456 opg < /opgactions/opg-backups/opgbackend.sql"
- docker compose exec app bash -c "chown -R application:application /opgactions"
- docker compose exec app bash -c "php artisan config:cache && php artisan route:cache && php artisan optimize"
48 changes: 48 additions & 0 deletions app/Console/Commands/InsertMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Console\Commands;

use App\Models\Game;
use App\Models\Item;
use Illuminate\Console\Command;

/* Not used anymore */

class InsertMedia extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:insert-media';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{
$items = Item::get();
foreach ($items as $item) {
if ($item->photos)
foreach ($item->photos as $photo) {
$item->addMediaFromDisk('item-photos/' . $item->id . '/' . $photo['id'] . '.jpg', 'public')->usingFileName(str_replace('/tmp/', '', tempnam(sys_get_temp_dir(), 'media-library')))->preservingOriginal()->toMediaCollection();
}
}

$games = Game::get();
foreach ($games as $game) {
if ($game->photos)
foreach ($game->photos as $photo) {
$game->addMediaFromDisk('game-photos/' . $game->id . '/' . $photo['id'] . '.jpg', 'public')->usingFileName(str_replace('/tmp/', '', tempnam(sys_get_temp_dir(), 'media-library')))->preservingOriginal()->toMediaCollection();
}
}
}
}
Loading

0 comments on commit c352edc

Please sign in to comment.