Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

troubles trying to deploy monorepro with pnpm with dockerfile and dokku #57

Closed
Jarrodsz opened this issue Jul 14, 2023 · 6 comments
Closed

Comments

@Jarrodsz
Copy link

Jarrodsz commented Jul 14, 2023

Before using this mono repro I had a working Dockerfile and did a git push dokku master.
That way it would spin up a dokku deployment using the Dockerfile in the root of the project.

Since I switched to pnpm I have not been able to figure out the correct way to deploy, even using gpt4 ( no phun intended ) i tryed to find the correct methodology to deploy my apps.

Even while its a monorepro im still very used to cd to the /apps/myapp folder and do a pnpm dev
The same goes for deployments. I would do a git push dokku master which would initiate the deployment, perhaps that is out of the scope of this repro and my question but deploying isent working at all.

This was my working Dockerfile:
https://gist.github.com/Jarrodsz/22ddc163d1cd8c628e6dd7597b042117

Now the problem even after changing this logical it still fails.
My modified pnpm version would assume to be:
https://gist.github.com/Jarrodsz/13fd50d2eb93914fec560e4364fec650

The problem is i seem to need to copy the package-lock.YAML file from the root of the mono repro, since it is not generated in my /mono_repro/apps/myapp/ folder.

GPT comes up with all kinds of obscure solutions not working.

What would be the correct way to gave an easy workflow for this?
I would like to just do a git push dokku master like im used to.

Is there way to generate the package-lock.yaml in the app folders somehow?
After 2 hours fiddling with the Dockerfile doing 100 deploys to test it and debug it I give up this is cybersome.

@Jarrodsz Jarrodsz changed the title troubles trying to deploy with dockerfile and dokku troubles trying to deploy monorepro with pnpm with dockerfile and dokku Jul 14, 2023
@Jarrodsz
Copy link
Author

Update, i found only the pnpm deploy command that generates a new clean working directory of a mono repro package.
Almost got it to work but not totally..

I wrote this bash script:
https://gist.github.com/Jarrodsz/2440a6bff5eec9cbd8aec93720c9bc38

That creates a new folder _deploy/my_app and then puts all mono repro code in it, i remove the dev dependencies and do a pnpm install for the @core packages im using.

The only problems is that

    "@core/core": "workspace:*",
    "@core/ui": "workspace:*",

Is still in my package.json.
It feels like im re-inventing the wheel a bit but since im using dokku and it expects the code in a certain format i don't know if there is a better way.

I now think i could scan my package.json for any "@core/core": "workspace:*", entries remove those and install the packages from the deploy directory manually running pnpm install @core/core instead. I assume that way they will be installed in that local deploy folder for the project.

BTW I create a new git init and add the git remote for dokku on each time the deploy command is run, i also make sure before to remove the whole ./deploy/$app_name path.

What do you think?

@PhilDL
Copy link
Owner

PhilDL commented Jul 16, 2023

Hi, sorry but I am a bit lost, I never used Dokku and assumed it was a using standard Docker images. Some general advice:

  • You shouldn't mix npm and pnpm in your Dockerfile, if you have a problem with the way pnpm installs dependencies you could add a .npmrc at the root of the project with:
prefer-workspace-packages=true
node-linker=hoisted
strict-peer-dependencies=false
auto-install-peers = true
  • I insist but every command should be run from the root of the folder.
  • If a command target a specific app in the monorepo you should use --filter=@org/nameofthepackage
  • If you move around deps, your pnpm lock file could be out of sync, to fix that, from the root of your monorepo run pnpm i --fix-lockfile
  • Turbo repo helps you build folder structure for Docker and correct package.json for the target app with turbo prune --scope=@remix-gospel-stack/remix-app --docker notice the --docker flag.
  • I feel that you are reinventing the wheel yes, the tools like pnpm and turborepo should actually help you.
  • If you feel that you begin to do too much outlandish stuff I would suggest you to recreate a simple monorepo that works with Dokku (if that's what you want), a simple empty Remix app, and just 1 package. Then slowly add complexity and see what the blocking points are, eventually, you would copy-paste every other packages you have in your repo and see when it begins to break.

Cannot help you more without looking into the whole project and trying for myself sorry!

@Jarrodsz
Copy link
Author

I got as far as

Get the name of the application from the command line argument.

app_name=$1

Check if the application exists.

app_dir=$(find ./apps/* -type d -name "$app_name" -print0 | xargs -0 ls)
if [ -z "$app_dir" ]; then
echo "App '$app_name' does not exist"
exit 1
fi

Check if the second argument is "test" and modify the output accordingly.

if [ "$2" = "test" ]; then
echo "Deploying test locally from apps/$app_name"
docker buildx build -t ${app_name} -f "apps/${app_name}/Dockerfile" .
else
echo "Deploying Production $app_name from apps/$app_name"
cd apps/$app_name
git add *
git commit -m 'deploy'
git push dokku master
fi```

The local test deployment works with this but requires each app to be faultless while one might be developing or refactoring code your unable go deploy or have to move in progress app out of /apps trmoporarily.

The dokku deployment still doesent work since it does not have access to local packages this way.

had a short break but already wasted another day on this not much feedback online so i probably end up dropping mono repro all together after spending lotts of time on it.

maybe you have some final thoughts on how i could make it work wirh dokku?

its just undeployable and the problem
Is pnpm turbo mono repro i feel so pissedoff wasting so much time on this and still not have been able to solve it🥲

@Jarrodsz
Copy link
Author

Full details here
vercel/turbo#5635

I posted this on turbo discord pnpm discord and renkx discord 10
Days ago but nobody seems to use dokku or seems to care so then the only option would be to drop turbo mono repro wirh pnpm, so sad if works awsome locally for most parts

@PhilDL
Copy link
Owner

PhilDL commented Jul 31, 2023

I understand your frustration but it's really hard to help you without seeing the full code, environment, etc... that I could pull and run locally.

Let's put dokku out of the equation for a moment, can you confirm that building AND running the Dockerfile locally works?
I mean running local commands that are similar to that (switching for your database, and your docker network)

docker build -t remix-gospel-stack-remix-app -f ./apps/remix-app/Dockerfile .
docker run -it --init --rm -p 3000:3000 --env-file .env.docker --env DATABASE_URL='postgresql://postgres:postgres@db:5432/postgres' --network=app_network remix-gospel-stack-remix-app

The app must be running and accessible through localhost:3000 locally when you docker run.

@Jarrodsz
Copy link
Author

I fixed this in the end sorry my excuse for never posting back lost track.

the solution was to deploy on a per app base the mino repro docs where misleading and putt me of guard. So what i do for dokku is have a seperate git for each alpp with a dockerfile and just do a git push remote. Which deploys the app.

will post a example config tomorrow.
Out of my head i just import the packages in the dockerfile so it does not break on them not be available from the single app perspective

@PhilDL PhilDL closed this as completed Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants