tomitrescak / meteor-uploads

MIT License
295 stars 41 forks source link

Files are lost on deploy #235

Closed msj121 closed 8 years ago

msj121 commented 8 years ago

The files that exist on the server are lost when "mup deploy" is run.

    UploadServer.init({
      tmpDir: process.env.PWD + '/.uploads/tmp',
      uploadDir: process.env.PWD + '/.uploads',
      checkCreateDirectories: true});

I think it is necessary to be able to re-upload the project without losing files...

tomitrescak commented 8 years ago

.uploads is not meteor dir and is ignored by meteor :/ that's why you upload there to avoid hot code push upon update

msj121 commented 8 years ago

Any ideas? Is this an issue with "mup deploy" deleting the files? Is there another solution/workaround?

Even if I remove the ".", I assume a deploy will always replace the folder contents with the local folder, so that is not a good solution for me; otherwise I might be willing to cause a reload on file upload, ridiculous, but anything to keep the files on a code update.

tomitrescak commented 8 years ago

If you want to retain files you need to upload to "public" dir which will cause hot code reload on every upload. Out of curiosity, why would you want to deploy uploaded files from develop? Just put all files that you need to public and upload into separate dir...

msj121 commented 8 years ago

I think there is a misunderstanding. I deploy the application than users can upload files, like their user profile picture. However, the next time I deploy all the files that they had uploaded are gone.

I am trying to figure out how to have a live website, that I can then update without destroying all of the users' files.

tomitrescak commented 8 years ago

Gotcha. Create an upload directory out of the app directory, e.g. /opt/var/uploads and set correct privileges. Then, use absolute path to point to that dir.

On Sunday, May 22, 2016, S notifications@github.com wrote:

I think there is a misunderstanding. I deploy the application than users can upload files, like their user profile picture. However, the next time I deploy all the files that they had uploaded are gone.

I am trying to figure out how to have a live website, that I can then update without destroying all of the users' files.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/tomitrescak/meteor-uploads/issues/235#issuecomment-220813885

Tomi Trescak / Researcher tomi.trescak@gmail.com / 0487 261 213

[image: Facebook] https://www.facebook.com/tomi.trescak[image: Twitter] https://twitter.com/tomitrescak[image: Google Plus] https://plus.google.com/112630384447746070397[image: Youtube] https://www.youtube.com/user/tomiiiino[image: Linkedin] https://www.linkedin.com/pub/tomas-trescak/34/b92/801?domainCountryName=&csrfToken=ajax%3A3648494742469937801 [image: skype]

msj121 commented 8 years ago

I have tried "/opt/uploads". I changed the directories with "chmod a+rwx /opt/uploads". Sadly, the files are uploaded (great), but I can't find them in that directory. I have no clue where they are going, but re-deploying once again destroys them.

I am uploading to DigitalOcean, I also looked through: https://github.com/tomitrescak/meteor-uploads/issues/40

I could find the files when it was set: process.env.PWD+"/uploads" ... and process.env.PWD = "bundle/bundle". Which is contained in "/opt/app name/current/bundle/uploads"

tomitrescak commented 8 years ago

As per documentation. If you set your server to following you will always find your files on /opt/uploads

//file:/server/init.js
Meteor.startup(function () {
  UploadServer.init({
    tmpDir: '/opt/uploads/tmp',
    uploadDir: '/opt/uploads/',
    checkCreateDirectories: true //create the directories for you
  });
});

Make sure you have good permissions,

nick-preda commented 8 years ago

If you are using mupx deploy, files that you upload will stay inside a docker container.

Whenever you redeploy your app, mupx will create a new docker container, so the files will be lost, each time. Discovered that the hard way

msj121 commented 8 years ago

Any ideas how to solve this? I don't seem to be able to access any folders outside of the docker container...

nick-preda commented 8 years ago

you should, some how, make a persistent docker only for the files, and somehow connect to the meteor docker. i personally didn't manage to do that

tomitrescak commented 8 years ago

Guys, you won't like the answer, but the best is to use the original mup not mupx that does not use docker. It still works well even with new meteor. The other option is to modify the mupx deploy script and add the parameter to mount external folder.

I see @nick-preda that you already tried to do that, what was your result?

tomitrescak commented 8 years ago

But from what I see it shall be easy to do, you need to modify the script at https://github.com/arunoda/meteor-up/blob/mupx/templates/linux/start.sh#L26

And add a new mapping. You can map multiple volumes such as following: http://stackoverflow.com/questions/18861834/mounting-multiple-volumes-on-a-docker-container

So your script would look like (mounting the folder on the host machine /opt/uploads/myapp to the folder /opt/uploads in the container):

docker run \
    -d \
    --restart=always \
    --publish=$PORT:80 \
    --volume=$BUNDLE_PATH:/bundle \
    --volume=/opt/uploads/myapp:/opt/uploads/ \                   .... this is the new line
    --env-file=$ENV_FILE \
    --link=mongodb:mongodb \
    --hostname="$HOSTNAME-$APPNAME" \
    --env=MONGO_URL=mongodb://mongodb:27017/$APPNAME \
    --name=$APPNAME \
    meteorhacks/meteord:base
msj121 commented 8 years ago

Awesome! Didn't actually know that was one of the key differences between mup and mupx. I'll be honest, my project kept throwing setup errors with mup, which is why I tried mupx and it worked.

THANK YOU so much, for finding this, I have been searching how to save stuff outside of the docker container, I was making progress, but this is WAY more helpful now.

msj121 commented 8 years ago

That worked for me. Thanks. I tested it just now.

nick-preda commented 8 years ago

i have no idea why, but now mup deploy works on my actual meteor setup. maybe because of the setup configuration on my new virtual machine...


i've got everything written down, if anyone wants to try again with mup:

i've created a new virtual machine, from which to deploy the meteor application ubuntu-14.04.4-server-amd64

and then executed these to install node: curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs

to install the desired node version through n sudo npm cache clean -f sudo npm install -g n sudo n 0.10.40

install meteor curl https://install.meteor.com/ | sh

and finally install mup sudo npm install -g mup

after which I successfully ran: mup setup and mup deploy

inserting nodeVersion 0.10.36 in mup.json, and deployCheckWaitTime to 120

you have also to give the right permissions to the upload folder, to be able to upload through mup.

hope it will help someone


i've been using mupx lately, since mup gave me huge trouble, but i'll still bookmark this answer @tomitrescak , as it's the solution to the docker setup.

thanks a lot