Question

access service from worker instance

I successfully created a worker using this https://docs.digitalocean.com/developer-center/how-to-setup-a-job-scheduler-on-digitalocean-app-platform/, while this is very easy and uses curl as an example, my problem is I need to run php script from the service instance so I need the crontab to access the service outside the worker container to run a php script e.g. /workspace/.heroku/php/bin/php /workspace/bin/console mautic:segments:update. I know I can access the internal service via exposed port 8080 by http://<name>:<port> but due to security concern, I would like to directly access the service rather than using http.

appspec is similar to this

alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
name: walrus-app
region: nyc
services:
- environment_slug: node-js
  git:
    branch: main
    repo_clone_url: https://github.com/digitalocean/sample-nodejs.git
  http_port: 8080
  instance_count: 1
  instance_size_slug: basic-xxs
  name: sample-nodejs
  routes:
  - path: /
  run_command: yarn start
  source_dir: /
workers:
- dockerfile_path: Dockerfile
  github:
    branch: main
    deploy_on_push: true
    repo: DO-Solutions/Docker-cron
  instance_count: 1
  instance_size_slug: basic-xxs
  name: Docker-cron
  source_dir: /

any help is greatly appreciated.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
May 20, 2023

Hi there,

I recently had a discussion about this here:

https://www.digitalocean.com/community/questions/laravel-scheduled-tasks

The documentation that you’ve shared gives a Node.js sample app as an example to trigger HTTP endpoints. In order for this to work, you need to get the files from the docker-cron repo and use the Dockerfile from the example repo as a blueprint and adjust it for your PHP project.

That way, rather than running the example curl command from the demo Node app, the Worker component will clone your PHP project and will have access to all of the necessary files.

There is a PHP Dockerfile example in the answer above.

The alternative option as you mentioned is to use the internal port and send HTTP requests instead.

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel