Skip to main content
Table of contents

Assets

Last updated: 23 Nov 2020

Manage assets

Removing an asset

If you need to remove an asset manually from assets.publishing.service.gov.uk, follow these steps:

  1. Mark the asset as deleted. Sometimes it may be necessary to completely scrub an asset from our systems e.g. if it contains secret information. In this case, add ,true to the appropriate rake task:
  1. Add a cache bust and check that the asset responds with a 404 not found

  2. Wait 20 minutes for the cache to clear, or purge it yourself

  3. Verify that the asset is not there

  4. Request removal of the asset using the Google Search Console

  5. Remove the asset from the mirrors:

    • Remove from AWS: gds aws govuk-production-poweruser aws s3 rm s3://govuk-production-mirror/assets.publishing.service.gov.uk/<slug>
    • Log into the GCP console
    • Go to the GOVUK Production project under the DIGITAL.CABINET-OFFICE.GOV.UK organisation
    • Select Storage -> Browser, manually delete the asset in the govuk-production-mirror bucket

Redirecting an asset

Sometimes it might be necessary to manually redirect an asset, for example if an associated document wasn't unpublished correctly. There are some Rake tasks available for this:

Uploading an asset

Some publishing apps such as Mainstream Publisher do not provide the facility for editors to upload assets such as images and PDFs. In these rare cases, we can upload assets to asset-manager manually and give the URL to content editors to embed.

Production assets are replicated to staging and integration nightly, so it is best to simply perform the upload directly in production. First, upload the asset to a backend machine:

$ gds govuk connect scp-push -e production aws/backend:1 my_file.jpg /tmp

Then SSH to the same machine and run the upload command:

$ gds govuk connect ssh -e production aws/backend:1
$ cd /var/apps/asset-manager
$ sudo -u deploy govuk_setenv asset-manager bin/create_asset /tmp/my_file.jpg

Note the basepath the script outputs. This should be appended to the asset host, for example:

https://assets.publishing.service.gov.uk/media/57358658ed915d58bd000000/my_file.jpg

Large attachments

Sometimes publishers ask us to help them upload very large attachments to documents in Whitehall because they see timeouts when they try to upload the document themselves.

The simplest way to do this is to upload a small file and then replace the file in Asset Manager.

Replacing an asset

If you need to replace the file of an existing attachment without changing the URL, follow these steps:

  1. Copy the new file from your computer to a backend server:

     $ gds govuk connect scp-push -e <environment> aws/backend:1 filename.ext /tmp
    
  2. Get an app console on that same server:

     $ gds govuk connect ssh -e <environment> aws/backend:1
     $ govuk_app_console asset-manager
    
  3. Find the asset:

     asset = Asset.find("asset-id-from-url") # e.g. `57a9c52b40f0b608a700000a`
     # or for a Whitehall asset:
     asset = WhitehallAsset.find_by(legacy_url_path: '/government/uploads/system/uploads/attachment_data/file/id/path.ext')
    
  4. Check the asset is what you think it is.

  5. Replace the file (change 123 to the new attachment size in bytes):

     asset.update(size: 123)
     asset.file = Pathname.new("/tmp/filename.ext").open
     asset.save!
    
  6. For a Whitehall attachment, update the file size in Whitehall, where 123 is the new attachment size in bytes:

    $ gds govuk connect app-console -e <environment> whitehall_backend/whitehall
    
    attachment = Attachment.find(asset-id-from-url) # e.g. 123456
    attachment.attachment_data.update(file_size: 123)