Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Storing Phoenix static assets on Amazon S3

I need to provide some context before asking the question:

CONTEXT

I have a Phoenix application that is being deployed to Heroku. As default, Brunch is being used to compile the Static Assets like .js,.css and images.

  • Those assets are stored on ./assets (as of Phoenix 1.3).
  • Those assets are compiled to ./priv/static/.

The compilation process generates a cache_manifest.json, after the assets are digested using MD5 fingerprinting.

It maybe important to notice I'm using CloudFlare's free version as a CDN.

I'm not concerned about user uploaded assets, I'm talking about the app's assets

Relevant part of the apps config/prod.exs

config :bespoke_work, BespokeWork.Web.Endpoint, 
  on_init: {BespokeWork.Web.Endpoint, :load_from_system_env, []},
  http: [port: {:system, "PORT"}],
  url: [scheme: "https", host: System.get_env("HEROKU_HOST"), port: System.get_env("HEROKU_PORT")],
  static_url: [scheme: "https", host: System.get_env("STATIC_ASSETS"), port: 443],
  force_ssl: [rewrite_on: [:x_forwarded_proto]],
  cache_static_manifest: "priv/static/cache_manifest.json",
  secret_key_base: System.get_env("SECRET_KEY_BASE")```

QUESTION

  1. How can I prevent Heroku from building the assets and, instead, during deploy, automatically upload the digested assets to an Amazon S3 Bucket?

  2. Will that make Heroku's slug smaller?


POSSIBLE SOLUTION

  1. Reducing Heroku's Slug Size:

    • On the Procfile redirect mix phx.digest to output digested items to /dev/null.

    or

    • Redefine mix deps.compile for Prod, not generating the assets.


  1. Generate the assets locally.

  1. Either Manually upload them or use a Shell Script to upload them to S3. (In my case probably using Codeship's Amazing Amazon S3 deployment)

  1. Use static_url to generate paths "pointing" to the S3 Bucket.

• Is there any simpler way to accomplish this? •

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This is not really a good idea... it might even be considered an anti-pattern.

But, if for some reason, that is absolutely necessary, this is one way to do it:

Reducing the Slug Size on Heroku:

  • Heroku allows the use of a .slugignore file for basic use cases (like .pdf or .psd)

    and / or

  • The slug cleaner buildpack cleans any non-required static assets after they've been processed.


Automating Amazon S3 Uploads

• This should be done through a shell script.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda