Files in shared/uploads directory not being uploaded on deploy

hi there,
the files in my shared/uploads directory are not being uploaded to my production server when I deploy and I’m not sure why.

I moved my assets / files from app/uploads into the shared directory like so:

shared/
└── uploads/
└── 2015/
└── 03/
- picture.jpg
- picture2.jpg

Now, I know (what I’m about to share) is backwards and not the correct way to get the files in the uploads directory to the production server but it worked. However, I know there must be a better way. So, I was able to get the files uploaded to the server by moving them into web/app/plugins/uploads directory, updated my .gitignore and then checked them all into my git repository before I ran $ bundle exec cap production deploy

Then after they were uploaded to web/app/plugins, I moved them into my /srv/www/domain.com/shared directory and then chomd 755 on the /srv/www/domain.com/shared/uploads.

Also, I made sure the following was in my deploy.rb file

set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads')

I know there must be a better way to get your uploads to the production server than the way I did? If someone would please share how to do so…I’d be VERY MUCH GRATEFUL.

Also, it should be noted that I ran the $ bundle exec cap production deploy command from my development environment and skipped deploying to a staging server…if it makes a difference?

Thanks in advance!

You should never be committing files into uploads/. There’s a reason it’s called “uploads” :smile:

Either they’re assets or uploads. If they’re assets, then commit them. If you do need to upload “uploads” to your server, just rsync/scp them outside of a deploy.

I guess on this topic…how do I prevent the uploads currently on the destination server from being lost when I do an bedrock-ansible deploy? The deploy of files works great but it wipes out all my uploads. I wouldn’t want to rsync after going live as the production database and uploads would be more current than my local.

Thanks,
Jason

They should be preserved.

See: https://github.com/roots/bedrock-ansible/blob/5890fc20b45821e20378a66c2a522a9ad35acf43/roles/deploy/defaults/main.yml#L46-L56

Uploads are kept in shared/uploads and symlinked on every deploy.

Hmmm. That doesn’t seem to be happening. I’m running ./deploy.sh staging stage.mysite.com from the ansible directory. It definitely empties out that directory each time I deploy.

Steps I took:

  1. Provisioned the server (Digital Ocean Droplet) for the first time a few minutes ago.
  2. Imported by database
  3. Ran the deploy about 5 times and each time my uploads were emptied

Thanks,
Jason

@jasonhjohnson it would be useful if you would provide some debugging information such as:

  1. your deploy log
  2. output of paths/directories on your server (such as shared/uploads and release uploads directories).

Not sure how you expect us to provide help without any information.

I didn’t mean to withhold detail from you. Perhaps it could have been a “just make sure you change this one value”-type of resolution.

Deploy log:

./deploy.sh staging stage.mysite.com

PLAY [Deploy WP site] *********************************************************

GATHERING FACTS *************************************************************** 
ok: [104.xxx.xx.xx]

TASK: [deploy | Initialize] *************************************************** 
ok: [104.xxx.xx.xx]

TASK: [deploy | Clone project files] ****************************************** 
changed: [104.xxx.xx.xx]

TASK: [deploy | write unfinished file] **************************************** 
changed: [104.xxx.xx.xx]

TASK: [deploy | Copy files to new build dir] ********************************** 
changed: [104.xxx.xx.xx]

TASK: [deploy | Move project subtree into root folder] ************************ 
skipping: [104.xxx.xx.xx]

TASK: [deploy | Remove unwanted files/folders from new release] *************** 
changed: [104.xxx.xx.xx] => (item=.git)

TASK: [deploy | Run pre_build_commands_local on Ansible host] ***************** 
changed: [104.xxx.xx.xx -> 127.0.0.1] => (item={'path': u'../site/web/app/themes/teamjb', 'cmd': 'npm install'})
changed: [104.xxx.xx.xx -> 127.0.0.1] => (item={'path': u'../site/web/app/themes/teamjb', 'cmd': 'bower install'})
changed: [104.xxx.xx.xx -> 127.0.0.1] => (item={'path': u'../site/web/app/themes/teamjb', 'cmd': 'gulp --production'})

TASK: [deploy | Copy project local files] ************************************* 
changed: [104.xxx.xx.xx -> 127.0.0.1] => (item={'dest': 'web/app/themes/teamjb', 'src': u'../site/web/app/themes/teamjb/dist', 'name': 'compiled theme assets'})

TASK: [deploy | Copy project templates] *************************************** 
changed: [104.xxx.xx.xx] => (item={'dest': '.env', 'src': 'roles/deploy/templates/env.j2', 'name': '.env config'})

TASK: [deploy | Run pre_build_commands in the new_release_path] *************** 
skipping: [104.xxx.xx.xx]

TASK: [deploy | Check if project folders exist] ******************************* 
ok: [104.xxx.xx.xx] => (item=vendor)

TASK: [deploy | Copy project folders] ***************************************** 
changed: [104.xxx.xx.xx] => (item={'invocation': {'module_name': u'stat', 'module_args': u'path="/srv/www/stage.mysite.com/current/vendor"'}, 'item': 'vendor', u'stat': {u'uid': 1000, u'exists': True, u'woth': False, u'mtime': 1434371997.2436776, u'inode': 264686, u'isgid': False, u'size': 4096, u'wgrp': False, u'isuid': False, u'isreg': False, u'pw_name': u'web', u'gid': 33, u'ischr': False, u'wusr': True, u'xoth': True, u'rusr': True, u'nlink': 8, u'issock': False, u'rgrp': True, u'gr_name': u'www-data', u'path': u'/srv/www/stage.mysite.com/current/vendor', u'xusr': True, u'atime': 1434371997.2436776, u'isdir': True, u'ctime': 1434371997.2436776, u'isblk': False, u'xgrp': True, u'dev': 64769, u'roth': True, u'isfifo': False, u'mode': u'0755', u'islnk': False}, u'changed': False})

TASK: [deploy | Ensure shared sources are present] **************************** 
ok: [104.xxx.xx.xx] => (item={'path': 'web/app/uploads', 'src': 'uploads'})

TASK: [deploy | Ensure shared paths are absent] ******************************* 
changed: [104.xxx.xx.xx] => (item={'path': 'web/app/uploads', 'src': 'uploads'})

TASK: [deploy | Create shared symlinks] *************************************** 
changed: [104.xxx.xx.xx] => (item={'path': 'web/app/uploads', 'src': 'uploads'})

TASK: [deploy | Run post_build_commands in the new_release_path] ************** 
changed: [104.xxx.xx.xx] => (item={'cmd': 'composer install --no-ansi --no-dev --no-interaction --no-progress --optimize-autoloader --no-scripts'})

TASK: [deploy | Finalize the deploy] ****************************************** 
changed: [104.xxx.xx.xx]

TASK: [deploy | Run post_finalize_commands] *********************************** 
changed: [104.xxx.xx.xx] => (item=sudo service php5-fpm reload)

TASK: [deploy | debug ] ******************************************************* 
ok: [104.xxx.xx.xx] => {
"msg": "master@c2abf93 deployed as release 20150615092055"
}

PLAY RECAP ******************************************************************** 
104.xxx.xx.xx : ok=18 changed=13 unreachable=0 failed=0 

Additionally, /shared/uploads folder just has 2015->06 and then this directory is empty.

Thanks,
Jason

Have you actually uploaded the uploads directory? Perhaps this is not described well enough in the documentation, but since uploads are not handled on deployment, you have to get them on the server.

2 Likes

That was the problem, Kalen! I knew it was something simple and yes I completely missed that step if that was mentioned somewhere in the documentation. Seems like a step 3a could be added to the list of deployment steps here: https://github.com/roots/bedrock-ansible#deploying-to-remote-servers mentioning this process. I’m sure you’re thinking I’m an idiot for even needing this step added, but, idiots abound.

-J

2 Likes