update docker
This commit is contained in:
		
							parent
							
								
									fa890743f3
								
							
						
					
					
						commit
						548eb9613c
					
				|  | @ -0,0 +1,2 @@ | ||||||
|  | node_modules/ | ||||||
|  | package-lock.json | ||||||
|  | @ -0,0 +1,13 @@ | ||||||
|  | FROM alpine:3.18 | ||||||
|  | 
 | ||||||
|  | RUN apk update --no-cache | ||||||
|  | RUN apk add --no-cache npm chromium | ||||||
|  | 
 | ||||||
|  | RUN mkdir /app | ||||||
|  | WORKDIR /app | ||||||
|  | 
 | ||||||
|  | COPY ./puppeteer.js /app/puppeteer.js | ||||||
|  | COPY ./server.js /app/server.js | ||||||
|  | COPY ./package.json /app/package.json | ||||||
|  | 
 | ||||||
|  | CMD sh -c 'npm i && node server.js' | ||||||
|  | @ -0,0 +1,5 @@ | ||||||
|  | { | ||||||
|  |   "dependencies": { | ||||||
|  |     "puppeteer": "^0.11.0" | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,39 @@ | ||||||
|  | const puppeteer = require('puppeteer'); | ||||||
|  | 
 | ||||||
|  | module.exports = async ( | ||||||
|  |   config = { url: '', screenshotPath: '', executablePath: '', timeout: 1000 } | ||||||
|  | ) => { | ||||||
|  | 
 | ||||||
|  |   config = Object.assign({ | ||||||
|  |     url: 'https://scrapingbee.com', | ||||||
|  |     screenshotPath: './screenshot.jpg', | ||||||
|  |     executablePath: '/usr/bin/chromium', | ||||||
|  |     timeout: 1000, | ||||||
|  |   }, config) | ||||||
|  | 
 | ||||||
|  |   const browser = await puppeteer.launch({ | ||||||
|  |     executablePath: config.executablePath, | ||||||
|  |     args: ['--no-sandbox', '--headless', '--disable-gpu'] | ||||||
|  |   }); | ||||||
|  |   const page = await browser.newPage(); | ||||||
|  | 
 | ||||||
|  |   // Set the viewport's width and height
 | ||||||
|  |   await page.setViewport({ width: 1920, height: 1080 }); | ||||||
|  | 
 | ||||||
|  |   // Open ScrapingBee's home page
 | ||||||
|  |   await page.goto(config.url); | ||||||
|  | 
 | ||||||
|  |   // Waiting Dom Ready
 | ||||||
|  |   await new Promise(r => setTimeout(r, config.timeout)); | ||||||
|  | 
 | ||||||
|  |   try { | ||||||
|  |     // Capture screenshot and save it in the current folder:
 | ||||||
|  |     await page.screenshot({ path: config.screenshotPath }); | ||||||
|  |     console.log(`Screenshot has been captured successfully`); | ||||||
|  | 
 | ||||||
|  |   } catch (err) { | ||||||
|  |     console.log(`Error: ${err.message}`); | ||||||
|  |   } finally { | ||||||
|  |     await browser.close(); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | @ -0,0 +1,55 @@ | ||||||
|  | const http = require('http'); | ||||||
|  | const url = require('url'); | ||||||
|  | const fs = require('fs'); | ||||||
|  | const puppeteer = require('./puppeteer'); | ||||||
|  | 
 | ||||||
|  | // Create an HTTP server
 | ||||||
|  | const server = http.createServer((req, res) => { | ||||||
|  |   const parseUrl = url.parse(req.url, true); | ||||||
|  | 
 | ||||||
|  |   const fail = (error) => { | ||||||
|  |     res.writeHead(200, {'Content-Type': 'application/json'}); | ||||||
|  |     res.end(JSON.stringify({ | ||||||
|  |       status: false, | ||||||
|  |       message: error | ||||||
|  |     })) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   const config = { | ||||||
|  |     screenshotPath: './screenshot2.jpg' | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   if (parseUrl.query.url) { | ||||||
|  |     config.url = parseUrl.query.url | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   try { | ||||||
|  |     puppeteer(config) | ||||||
|  |       .then(function() { | ||||||
|  |         fs.readFile(config.screenshotPath, (err, data) => { | ||||||
|  |           if (err) { | ||||||
|  |             res.writeHead(500); | ||||||
|  |             res.end('Internal Server Error'); | ||||||
|  |           } else { | ||||||
|  |             res.writeHead(200, {'Content-Type': 'image/jpeg'}); | ||||||
|  |             res.end(data); | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |       }) | ||||||
|  |       .catch(function(error) { | ||||||
|  |         fail(error.toString()) | ||||||
|  |       }); | ||||||
|  |   } catch (error) { | ||||||
|  |     fail(error.toString()) | ||||||
|  |   } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | // Set the port to listen to
 | ||||||
|  | const port = process.env.PORT || 4000; | ||||||
|  | const host = '0.0.0.0'; // Listen on all network interfaces
 | ||||||
|  | 
 | ||||||
|  | // Start the server
 | ||||||
|  | server.listen(port, host, () => { | ||||||
|  |   console.log(`Server running at http://${host}:${port}/`); | ||||||
|  | }); | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | node_modules/ | ||||||
|  | package-lock.json | ||||||
|  | @ -0,0 +1,12 @@ | ||||||
|  | FROM alpine:3.18 | ||||||
|  | 
 | ||||||
|  | RUN apk update | ||||||
|  | RUN apk add --no-cache npm | ||||||
|  | 
 | ||||||
|  | RUN mkdir /socketio | ||||||
|  | WORKDIR /socketio | ||||||
|  | COPY ./server.js /socketio | ||||||
|  | COPY ./package.json /socketio | ||||||
|  | 
 | ||||||
|  | EXPOSE 3000 | ||||||
|  | CMD sh -c 'npm i && node server.js' | ||||||
|  | @ -0,0 +1,21 @@ | ||||||
|  | // Import Socket.IO client library
 | ||||||
|  | const io = require('socket.io-client'); | ||||||
|  | 
 | ||||||
|  | // URL of the Socket.IO server
 | ||||||
|  | const serverUrl = 'http://localhost:3000'; | ||||||
|  | 
 | ||||||
|  | // Connect to the server
 | ||||||
|  | const socket = io(serverUrl); | ||||||
|  | 
 | ||||||
|  | // Event handler for successful connection
 | ||||||
|  | socket.on('connect', () => { | ||||||
|  |     console.log('Connected to server'); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | // Event handler for receiving messages from the server
 | ||||||
|  | socket.on('message', (data) => { | ||||||
|  |     console.log('Received message from server:', data); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | // Sending a message to the server
 | ||||||
|  | socket.emit('message', 'Hello, server!'); | ||||||
|  | @ -0,0 +1,6 @@ | ||||||
|  | { | ||||||
|  |   "dependencies": { | ||||||
|  |     "socket.io": "^4.7.4", | ||||||
|  |     "socket.io-client": "^4.7.4" | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,29 @@ | ||||||
|  | const httpServer = require("http").createServer(); | ||||||
|  | const io = require("socket.io")(httpServer, { | ||||||
|  |   // ...
 | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | io.on("connection", (socket) => { | ||||||
|  | 
 | ||||||
|  |     console.log('Connected'); | ||||||
|  | 
 | ||||||
|  |     // Handle data received from the client
 | ||||||
|  |     socket.on('data', (data) => { | ||||||
|  |         console.log('Received:', data.toString()); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     socket.on('message', (data) => { | ||||||
|  |         console.log('Received:', data.toString()); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     // Handle when the client disconnects
 | ||||||
|  |     socket.on('end', () => { | ||||||
|  |         console.log('Client disconnected'); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | const port = process.env.PORT || 3000; | ||||||
|  | const host = '0.0.0.0'; | ||||||
|  | httpServer.listen(port, host, () => { | ||||||
|  |   console.log(`Server running on port ${host}:${port}`); | ||||||
|  | }); | ||||||
|  | @ -1,87 +0,0 @@ | ||||||
| on: |  | ||||||
|   push: |  | ||||||
|     branches: |  | ||||||
|       - master |  | ||||||
|   pull_request_target: |  | ||||||
|     types: [opened, synchronize, reopened] |  | ||||||
| 
 |  | ||||||
| name: CodeSee Map |  | ||||||
| 
 |  | ||||||
| jobs: |  | ||||||
|   test_map_action: |  | ||||||
|     runs-on: ubuntu-latest |  | ||||||
|     continue-on-error: true |  | ||||||
|     name: Run CodeSee Map Analysis |  | ||||||
|     steps: |  | ||||||
|       - name: checkout |  | ||||||
|         id: checkout |  | ||||||
|         uses: actions/checkout@v2 |  | ||||||
|         with: |  | ||||||
|           repository: ${{ github.event.pull_request.head.repo.full_name }} |  | ||||||
|           ref: ${{ github.event.pull_request.head.ref }} |  | ||||||
|           fetch-depth: 0 |  | ||||||
| 
 |  | ||||||
|       # codesee-detect-languages has an output with id languages. |  | ||||||
|       - name: Detect Languages |  | ||||||
|         id: detect-languages |  | ||||||
|         uses: Codesee-io/codesee-detect-languages-action@latest |  | ||||||
| 
 |  | ||||||
|       - name: Configure JDK 16 |  | ||||||
|         uses: actions/setup-java@v2 |  | ||||||
|         if: ${{ fromJSON(steps.detect-languages.outputs.languages).java }} |  | ||||||
|         with: |  | ||||||
|           java-version: '16' |  | ||||||
|           distribution: 'zulu' |  | ||||||
| 
 |  | ||||||
|       # CodeSee Maps Go support uses a static binary so there's no setup step required. |  | ||||||
| 
 |  | ||||||
|       - name: Configure Node.js 14 |  | ||||||
|         uses: actions/setup-node@v2 |  | ||||||
|         if: ${{ fromJSON(steps.detect-languages.outputs.languages).javascript }} |  | ||||||
|         with: |  | ||||||
|           node-version: '14' |  | ||||||
| 
 |  | ||||||
|       - name: Configure Python 3.x |  | ||||||
|         uses: actions/setup-python@v2 |  | ||||||
|         if: ${{ fromJSON(steps.detect-languages.outputs.languages).python }} |  | ||||||
|         with: |  | ||||||
|           python-version: '3.10' |  | ||||||
|           architecture: 'x64' |  | ||||||
| 
 |  | ||||||
|       - name: Configure Ruby '3.x' |  | ||||||
|         uses: ruby/setup-ruby@v1 |  | ||||||
|         if: ${{ fromJSON(steps.detect-languages.outputs.languages).ruby }} |  | ||||||
|         with: |  | ||||||
|           ruby-version: '3.0' |  | ||||||
| 
 |  | ||||||
|       # We need the rust toolchain because it uses rustc and cargo to inspect the package |  | ||||||
|       - name: Configure Rust 1.x stable |  | ||||||
|         uses: actions-rs/toolchain@v1 |  | ||||||
|         if: ${{ fromJSON(steps.detect-languages.outputs.languages).rust }}  |  | ||||||
|         with: |  | ||||||
|           toolchain: stable |  | ||||||
| 
 |  | ||||||
|       - name: Generate Map |  | ||||||
|         id: generate-map |  | ||||||
|         uses: Codesee-io/codesee-map-action@latest |  | ||||||
|         with: |  | ||||||
|           step: map |  | ||||||
|           api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} |  | ||||||
|           github_ref: ${{ github.ref }} |  | ||||||
|           languages: ${{ steps.detect-languages.outputs.languages }} |  | ||||||
| 
 |  | ||||||
|       - name: Upload Map |  | ||||||
|         id: upload-map |  | ||||||
|         uses: Codesee-io/codesee-map-action@latest |  | ||||||
|         with: |  | ||||||
|           step: mapUpload |  | ||||||
|           api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} |  | ||||||
|           github_ref: ${{ github.ref }} |  | ||||||
| 
 |  | ||||||
|       - name: Insights |  | ||||||
|         id: insights |  | ||||||
|         uses: Codesee-io/codesee-map-action@latest |  | ||||||
|         with: |  | ||||||
|           step: insights |  | ||||||
|           api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} |  | ||||||
|           github_ref: ${{ github.ref }} |  | ||||||
|  | @ -1,6 +1,10 @@ | ||||||
| version : '3' | version : '3' | ||||||
|  | 
 | ||||||
|  | name: laravel-rabbitmq | ||||||
|  | 
 | ||||||
| networks: | networks: | ||||||
|   laravel: |   laravel: | ||||||
|  | 
 | ||||||
| services: | services: | ||||||
|   app: |   app: | ||||||
|     tty: true |     tty: true | ||||||
|  | @ -12,10 +16,18 @@ services: | ||||||
|       - 1000:8000 |       - 1000:8000 | ||||||
|       - 1001:8001 |       - 1001:8001 | ||||||
|     networks: |     networks: | ||||||
|       - laravel |       laravel: | ||||||
|     depends_on: |     depends_on: | ||||||
|       - redis |       - redis | ||||||
| 
 | 
 | ||||||
|  |   puppeteer: | ||||||
|  |     build: | ||||||
|  |       context: ./.docker/puppeteer | ||||||
|  |       dockerfile: Dockerfile | ||||||
|  |     ports: | ||||||
|  |       - 4000:4000 | ||||||
|  |     shm_size: '256M' | ||||||
|  | 
 | ||||||
|   redis: |   redis: | ||||||
|     image: redis |     image: redis | ||||||
|     container_name: redis |     container_name: redis | ||||||
|  |  | ||||||
|  | @ -4,6 +4,8 @@ APP_KEY=base64:S0K/eYkvLZYwMvP7CDU6HoII9UmcTGmif9lZepsoSFs= | ||||||
| APP_DEBUG=true | APP_DEBUG=true | ||||||
| APP_URL=http://localhost | APP_URL=http://localhost | ||||||
| 
 | 
 | ||||||
|  | SOCKET_IO=http://socketio:3000 | ||||||
|  | 
 | ||||||
| LOG_CHANNEL=stack | LOG_CHANNEL=stack | ||||||
| LOG_DEPRECATIONS_CHANNEL=null | LOG_DEPRECATIONS_CHANNEL=null | ||||||
| LOG_LEVEL=debug | LOG_LEVEL=debug | ||||||
|  |  | ||||||
|  | @ -0,0 +1,47 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace App\Console\Commands; | ||||||
|  | 
 | ||||||
|  | use ElephantIO\Client; | ||||||
|  | use ElephantIO\Engine\SocketIO\Version2X; | ||||||
|  | use ElephantIO\Engine\SocketIO\Version4X; | ||||||
|  | use Illuminate\Console\Command; | ||||||
|  | 
 | ||||||
|  | class Socket extends Command | ||||||
|  | { | ||||||
|  |     /** | ||||||
|  |      * The name and signature of the console command. | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     protected $signature = 'socket'; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * The console command description. | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     protected $description = 'Command description'; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Execute the console command. | ||||||
|  |      * | ||||||
|  |      * @return int | ||||||
|  |      */ | ||||||
|  |     public function handle() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $url = env('SOCKET_IO'); | ||||||
|  | 
 | ||||||
|  |         // if client option is omitted then it will use latest client available,
 | ||||||
|  | 
 | ||||||
|  |         $client = new Client(new Version4X($url)); | ||||||
|  |         $client->connect(); | ||||||
|  | 
 | ||||||
|  |         // Sending a message to the server
 | ||||||
|  |         $client->emit('message', ['Hello, server!']); | ||||||
|  | 
 | ||||||
|  |         // Close the connection when done
 | ||||||
|  |         $client->disconnect(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
|     "license": "MIT", |     "license": "MIT", | ||||||
|     "require": { |     "require": { | ||||||
|         "php": "^8.0.2", |         "php": "^8.0.2", | ||||||
|  |         "elephantio/elephant.io": "^4.7", | ||||||
|         "guzzlehttp/guzzle": "^7.2", |         "guzzlehttp/guzzle": "^7.2", | ||||||
|         "laravel/framework": "^9.19", |         "laravel/framework": "^9.19", | ||||||
|         "laravel/horizon": "^5.22", |         "laravel/horizon": "^5.22", | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ | ||||||
|         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||||
|         "This file is @generated automatically" |         "This file is @generated automatically" | ||||||
|     ], |     ], | ||||||
|     "content-hash": "97efdeb4e149ae370ca39b1992647562", |     "content-hash": "25b944829f758ab8566122440a9ef34e", | ||||||
|     "packages": [ |     "packages": [ | ||||||
|         { |         { | ||||||
|             "name": "brick/math", |             "name": "brick/math", | ||||||
|  | @ -501,6 +501,81 @@ | ||||||
|             ], |             ], | ||||||
|             "time": "2023-10-06T06:47:41+00:00" |             "time": "2023-10-06T06:47:41+00:00" | ||||||
|         }, |         }, | ||||||
|  |         { | ||||||
|  |             "name": "elephantio/elephant.io", | ||||||
|  |             "version": "v4.7.0", | ||||||
|  |             "source": { | ||||||
|  |                 "type": "git", | ||||||
|  |                 "url": "https://github.com/ElephantIO/elephant.io.git", | ||||||
|  |                 "reference": "4b2f8f044c815c6c5b7c989cc2e18a370718e55f" | ||||||
|  |             }, | ||||||
|  |             "dist": { | ||||||
|  |                 "type": "zip", | ||||||
|  |                 "url": "https://api.github.com/repos/ElephantIO/elephant.io/zipball/4b2f8f044c815c6c5b7c989cc2e18a370718e55f", | ||||||
|  |                 "reference": "4b2f8f044c815c6c5b7c989cc2e18a370718e55f", | ||||||
|  |                 "shasum": "" | ||||||
|  |             }, | ||||||
|  |             "require": { | ||||||
|  |                 "ext-mbstring": "*", | ||||||
|  |                 "php": ">=7.2", | ||||||
|  |                 "psr/log": "^1.1 || ^3.0" | ||||||
|  |             }, | ||||||
|  |             "require-dev": { | ||||||
|  |                 "friendsofphp/php-cs-fixer": "^3.0", | ||||||
|  |                 "monolog/monolog": "^2.8 || ^3.0", | ||||||
|  |                 "phpunit/phpunit": "^8.5 || ^9.5" | ||||||
|  |             }, | ||||||
|  |             "type": "library", | ||||||
|  |             "autoload": { | ||||||
|  |                 "psr-4": { | ||||||
|  |                     "ElephantIO\\": "src/" | ||||||
|  |                 } | ||||||
|  |             }, | ||||||
|  |             "notification-url": "https://packagist.org/downloads/", | ||||||
|  |             "license": [ | ||||||
|  |                 "MIT" | ||||||
|  |             ], | ||||||
|  |             "authors": [ | ||||||
|  |                 { | ||||||
|  |                     "name": "Baptiste Clavié", | ||||||
|  |                     "email": "baptiste@wisembly.com", | ||||||
|  |                     "homepage": "http://baptiste.xn--clavi-fsa.net/", | ||||||
|  |                     "role": "Maintainer" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Guillaume Potier", | ||||||
|  |                     "email": "guillaume@wisembly.com", | ||||||
|  |                     "role": "Maintainer" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Toha", | ||||||
|  |                     "email": "tohenk@yahoo.com", | ||||||
|  |                     "role": "Maintainer" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Ludovic Barreca", | ||||||
|  |                     "email": "ludogp2@gmail.com", | ||||||
|  |                     "role": "Project Founder" | ||||||
|  |                 }, | ||||||
|  |                 { | ||||||
|  |                     "name": "Elephant.IO Community", | ||||||
|  |                     "role": "Contributors :)" | ||||||
|  |                 } | ||||||
|  |             ], | ||||||
|  |             "description": "Send events to a socket.io server through PHP", | ||||||
|  |             "homepage": "https://elephantio.github.io/elephant.io/", | ||||||
|  |             "keywords": [ | ||||||
|  |                 "Socket.io", | ||||||
|  |                 "dialog", | ||||||
|  |                 "nodejs", | ||||||
|  |                 "real time", | ||||||
|  |                 "websocket" | ||||||
|  |             ], | ||||||
|  |             "support": { | ||||||
|  |                 "source": "https://github.com/ElephantIO/elephant.io/tree/v4.7.0" | ||||||
|  |             }, | ||||||
|  |             "time": "2024-02-16T19:40:38+00:00" | ||||||
|  |         }, | ||||||
|         { |         { | ||||||
|             "name": "fruitcake/php-cors", |             "name": "fruitcake/php-cors", | ||||||
|             "version": "v1.3.0", |             "version": "v1.3.0", | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| <?php | <?php | ||||||
| 
 | 
 | ||||||
|  | use ElephantIO\Client; | ||||||
| use Illuminate\Support\Facades\Route; | use Illuminate\Support\Facades\Route; | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
|  | @ -11,10 +12,11 @@ use Illuminate\Support\Facades\Route; | ||||||
| | routes are loaded by the RouteServiceProvider within a group which | | routes are loaded by the RouteServiceProvider within a group which | ||||||
| | contains the "web" middleware group. Now create something great! | | contains the "web" middleware group. Now create something great! | ||||||
| | | | | ||||||
| */ |  */ | ||||||
| 
 | 
 | ||||||
| Route::get('/', function () { | Route::get('/', function () { | ||||||
|     return view('welcome'); |     return view('welcome'); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| Route::view('/socket', 'socket'); | Route::get('/socket', function () { | ||||||
|  | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue