Skip to content

Commit

Permalink
Merge pull request #1 from Sammyjo20/feature/framework
Browse files Browse the repository at this point in the history
Feature | Turn into a framework
  • Loading branch information
Sammyjo20 authored Jul 27, 2024
2 parents 689dd9d + 9256759 commit 7205255
Show file tree
Hide file tree
Showing 24 changed files with 465 additions and 161 deletions.
2 changes: 2 additions & 0 deletions .docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

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

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.github export-ignore
/tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpunit.xml export-ignore
.php-cs-fixer.dist.php export-ignore
phpstan.baseline.neon export-ignore
phpstan.dist.neon export-ignore
35 changes: 35 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div align="center">

# 🤫 _`SSH PHP` !_

### The ridiculously simple framework for building PHP SSH apps! 🔥

<img width="974" alt="Screenshot 2024-07-26 at 18 09 49" src="https://github.com/user-attachments/assets/cdecc8fb-ba0f-4c0d-8aff-9e43f539f3f3">

</div>

> This project is in early access, and I'm quite new to Docker so please consider contributing if you think this could be improved! Please share your thoughts in the issues/discussions. Thank you!
# What the shell?!

I know right! I've just ran `ssh localhost` and I've got a full PHP application running in my terminal?! What! Me too. When I first saw [Joe Tannenbaum's](https://joe.codes/) Tweet where he showed off his awesome `ssh cli.lab.joe.codes` I thought to myself, I had to get this working myself. I have a secret project that I'm currently working on but during my research I managed to adapt his guide for getting [charmbracelet/wish](https://github.com/charmbracelet/wish) running with PHP to work with Docker!

# Why?
This is mainly for building [TUIs](https://en.wikipedia.org/wiki/Text-based_user_interface) however it can run any PHP script so you can build cool forms, resumes or anything you desire!

# Why Docker?

Well, messing around with SSH is not really something I want to do to my servers. Additionally, if I'm going to have the public **SSH into my server** I'm going to want to make sure it's ring-fenced. With a Docker container, it's even more ring-fenced then just SSHing directly into the server.

# Installation
To get started, run the following Composer installation command

```
composer create-project sammyjo20/ssh-php ssh-app-name
```

# Deploying to production

### Credits

- Huge thanks to [Joe Tannenbaum's](https://joe.codes/) for his awesome [blog post](https://blog.joe.codes/creating-ssh-apps-with-charm-wish-and-laravel-prompts) and his support via Twitter/X DMs!
28 changes: 28 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Code Style

on:
push:
branches:
- 'main'
pull_request:
branches:
- '*'

permissions:
contents: write

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 🪄 Code Style Fixes
28 changes: 28 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PHPStan

on:
push:
branches:
- 'main'
pull_request:
branches:
- '*'

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v2

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --error-format=github
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests

on:
push:
branches:
- 'main'
pull_request:
branches:
- '*'

permissions:
contents: read

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.3 ]
stability: [ prefer-lowest, prefer-stable ]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
# extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: ./vendor/bin/pest
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@
/.idea
/.vscode

# SSH Config
data/.ssh
# Project dependencies
/vendor
/composer.lock

# Caches, externally stored stuff, etc
.php-cs-fixer.cache
.phpunit.result.cache
tests/Fixtures/Saloon

# environments/configs
phpstan.neon
48 changes: 48 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__,
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude(['vendor', 'node_modules']);

$config = new PhpCsFixer\Config();

// Rules from: https://cs.symfony.com/doc/rules/index.html

return $config->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'length'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'single_quote' => ['strings_containing_single_quote_chars' => true],
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'return_type_declaration' => [
'space_before' => 'none'
],
'declare_strict_types' => true,
'blank_line_after_opening_tag' => true,
'single_import_per_statement' => true,
'mb_str_functions' => true,
'no_superfluous_phpdoc_tags' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'phpdoc_trim' => true,
])->setFinder($finder);
34 changes: 11 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
FROM ubuntu:24.04
FROM sammyjo20/ssh-php:latest

# Install Go
# Install Composer

RUN apt update && apt install golang git php php-cli sudo -y
RUN apt update && apt install composer -y

RUN export PATH=$PATH:/usr/local/bin/go
# Copy all files

# Copy our very basic script
COPY ./src /app/php/src
COPY ./composer.json /app/php
COPY ./composer.lock /app/php

COPY ./src/go/main.go .
# Create a symbolic link

RUN go mod init sammyjo20/jourminal
RUN ln -s /app/php/src/index.php /app/php/index.php

# Install Dependencies
# Run Composer install without dependencies

RUN go get github.com/charmbracelet/log \
github.com/charmbracelet/ssh \
github.com/charmbracelet/wish \
github.com/charmbracelet/wish/logging \
github.com/creack/pty

# Build the image

RUN env go build main.go

# Expose Port 22

EXPOSE 22

ENTRYPOINT ["./main"]
RUN cd /app/php && composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
37 changes: 0 additions & 37 deletions README.md

This file was deleted.

50 changes: 50 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "sammyjo20/ssh-php",
"description": "The ridiculously simple framework for building PHP SSH apps! 🔥",
"type": "project",
"require": {
"php": "^8.3",
"laravel/prompts": "^0.1.24",
"nunomaduro/termwind": "^2.0",
"joetannenbaum/chewie": "^0.1.2"
},
"autoload": {
"psr-4": {
"App\\": "./src/app"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "./tests"
}
},
"authors": [
{
"name": "Your Name",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.60",
"phpstan/phpstan": "^1.11",
"pestphp/pest": "^2.34",
"symfony/var-dumper": "^7.1"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"scripts": {
"fix-code": [
"./vendor/bin/php-cs-fixer fix --allow-risky=yes"
],
"pstan": [
"./vendor/bin/phpstan analyse"
],
"test": [
"./vendor/bin/pest"
]
}
}
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ services:
build:
context: .
volumes:
- ./data/.ssh:/.ssh
- ./src/php:/app/php
- ./.docker/.ssh:/.ssh
ports:
- 2201:22 # Change to 22:22 if you don't have an SSH server running already
restart: unless-stopped
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
14 changes: 14 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#############################################################################################
# Don't edit this config file directly. #
# For temporary, or local overrides, create a file named 'phpstan.neon' alongside this one. #
#############################################################################################

parameters:
# Add one of the editorUrl's in your phpstan.neon file for direct editor/IDE links in the terminal.
#editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
#editorUrl: 'vscode://file/%%file%%:%%line%%'

level: 6

paths:
- src
Loading

0 comments on commit 7205255

Please sign in to comment.