budget icon indicating copy to clipboard operation
budget copied to clipboard

148 Docker image (Web + Cron + PHP)

Open saschahemleb opened this issue 4 years ago • 14 comments

This PR will extend our application docker image:

  • NGINX, so we can get rid of the nginx service in docker-compose.yml
  • crond, now laravels scheduler should work ootb
  • php-fpm (as before)
  • supervisord as our init

There are a few gotchas:

  • Because we now include a .dockerignore, a few host files aren't included in the image anymore. Most prominent is the .env file, which was used by the docker-compose setup to set the APP_ENV, APP_KEY etc. It's probably fine to just address it in the README accordingly

  • The image is now build in multiple stages and I pulled all the npm stuff into their own stage. Upside is that we do not need the npm tools in our final image. But if someone or something was relying on those tools they are out of luck now.

saschahemleb avatar Jun 25 '20 21:06 saschahemleb

Is this a functional Docker image? I haven't tried it yet, but it seems promising enough to try and get it set up.

Also, take a look at your commits, I think the author is fucky? 😛

range-of-motion avatar Jul 01 '20 21:07 range-of-motion

Is this a functional Docker image? I haven't tried it yet, but it seems promising enough to try and get it set up.

Also, take a look at your commits, I think the author is fucky? 😛

Thanks for letting me know about the author, I fixed it.

And yeah, as far as I can tell everything is working with the image. I hadn't had time to test if the schedules are working, so a maybe for the crond stuff. But other than that the image is good to go!

saschahemleb avatar Jul 02 '20 07:07 saschahemleb

Trying the image right now. For some reason it keeps saying SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO), while I specify the DB_HOST explicitly (as seen below).

docker build --no-cache -t testing_sascha . && docker run --env DB_HOST=host.docker.internal -it testing_sascha

Any ideas? Can you walk me through the steps it took to get it working for you?

range-of-motion avatar Jul 02 '20 19:07 range-of-motion

You are missing the other environment variables for the database connection, for example DB_USERNAME and DB_PASSWORD. If you want to run it standalone you have to provide those too.

Another way would be to use the docker-compose.yml, that's how I tested it. Make sure the .env file is loaded by docker (which is configured correctly if you use my latest branch).

saschahemleb avatar Jul 03 '20 07:07 saschahemleb

Is this the docker container I should be using or the other PR?

Facinorous-420 avatar Jul 08 '20 18:07 Facinorous-420

Is this the docker containers I should be using or the other PR?

Depends on what you mean by "using". This is one of the candidates for the Docker image, but you can use it already if you want.

range-of-motion avatar Jul 08 '20 18:07 range-of-motion

Ah, thanks for your comment @saschahemleb, I got it working. I think this looks pretty good.

What am I supposed to do with the .env? It doesn't exist after I clone the repository, should I manually create it and run php artisan key:generate, or is that something the Docker image should do?

range-of-motion avatar Jul 27 '20 21:07 range-of-motion

@saschahemleb seems like this PR is the winner in the vote, and can therefor become the Docker image for this project.

  • Can you modify the instructions for Docker in README.md?
  • Do you want to keep the docker-compose.yml, as well as the database server that's inside?

range-of-motion avatar Jul 28 '20 16:07 range-of-motion

Hey, sounds good to me.

Regarding the APP_KEY/.env: The key should be fairly static in a live environment, so the generation during container startup is a no go, at least without persisting the key someway. For someone just cloning the repo and running a docker-compose up I will add a note in the README. It boils down to copying .env.example to .env, reviewing and changing any existing value (and adding a key).

We can keep the docker-compose.yml for now. It's a good starting point for quickly spinning up an environment.

I will push some changes to the README tonight as well so this can be merged soon.

saschahemleb avatar Jul 28 '20 19:07 saschahemleb

Great work @saschahemleb.

Would this also allow users to set up PGID and PUID as env variables, for easy permission mapping to bind mounts? The way LSIO does it is by far the best method in my experience: https://docs.linuxserver.io/general/understanding-puid-and-pgid

recklessnl avatar Jul 30 '20 02:07 recklessnl

Great work @saschahemleb.

Would this also allow users to set up PGID and PUID as env variables, for easy permission mapping to bind mounts? The way LSIO does it is by far the best method in my experience: https://docs.linuxserver.io/general/understanding-puid-and-pgid

Hey @recklessnl,

maybe I'm missing something but what are you binding into the container that is used by budget?

I intentionally left any user/group id stuff out of this as I saw no use for that.

saschahemleb avatar Jul 30 '20 13:07 saschahemleb

I think this is almost done. Sorry it took so long for me to review it.

It took it for another spin tonight, and it mostly works. I think the remaining to-do's are as follows.

  • There is an error about the version of nginx-light not being found (do you have that too?)
  • Perhaps a rebase on master, but I don't know if that's truly necessary 🤷
  • Clean up instructions for README.md (remove any dots and backslashes at the end of the lines, so it's the same as the other instructions in that file)
  • Squash commits into a few (or single) commit (something like "Rework Dockerfile", whatever)

If anyone has something to say that I missed, please speak up 🙂

range-of-motion avatar Sep 30 '20 21:09 range-of-motion

There is an error about the version of nginx-light not being found (do you have that too?)

Yeah I get that too. This specific version of the nginx-light package does not exist in the debian repository anymore. I'll remove the version constraints for now. Debian itself wouldn't allow major version upgrades in the same release so there is no need for us to force the package version.

saschahemleb avatar Oct 01 '20 12:10 saschahemleb

It looks pretty decent to me, I'm thinking of accepting it.

Anyone else that has something to say?

range-of-motion avatar Oct 01 '20 21:10 range-of-motion

Going to close this as it's a bit stale, and we've had a Docker setup for a while now. That being said, I greatly appreciate the time and effort everybody put in here. Thanks 🙏

range-of-motion avatar Mar 28 '23 23:03 range-of-motion