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

[PR] Adding env variables to deploy workflow so compile_env works. #102

Merged
merged 11 commits into from
Jul 19, 2023
Merged
6 changes: 5 additions & 1 deletion .github/workflows/fly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main

jobs:
deploy:
name: Deploy app
Expand All @@ -14,4 +15,7 @@ jobs:
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
AWS_REGION: eu-west-3
LuchoTurtle marked this conversation as resolved.
Show resolved Hide resolved
AWS_S3_BUCKET_ORIGINAL: imgup-original
AWS_S3_BUCKET_COMPRESSED: imgup-compressed
9 changes: 7 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ add:
{:ok, upload_response_body} =
image.path
|> ExAws.S3.Upload.stream_file()
|> ExAws.S3.upload(@original_bucket, file_name,
|> ExAws.S3.upload(Application.get_env(:ex_aws, :original_bucket), file_name,
nelsonic marked this conversation as resolved.
Show resolved Hide resolved
acl: :public_read,
content_type: image.content_type
)
Expand Down Expand Up @@ -710,8 +710,13 @@ making it simpler!
# Fetch the contents of the returned XML string from `ex_aws`.
# This XML is parsed with `sweet_xml`:
# github.com/kbrw/sweet_xml#the-x-sigil
#
# Fetching the URL of the returned file.
url = upload_response_body.body |> xpath(~x"//text()") |> List.to_string()
compressed_url = "#{@compressed_baseurl}#{file_name}"

# Creating the compressed URL to return as well
compressed_bucket_baseurl = "https://s3.eu-west-3.amazonaws.com/#{Application.get_env(:ex_aws, :compressed_bucket)}/"
compressed_url = "#{compressed_bucket_baseurl}#{file_name}"
{:ok, %{url: url, compressed_url: compressed_url}}
else
{:error, reason} -> {:error, reason}
Expand Down
12 changes: 6 additions & 6 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ if config_env() == :prod do

# https://github.com/dwyl/imgup/issues/68
config :ex_aws,
access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY"),
region: System.get_env("AWS_REGION"),
original_bucket: System.get_env("AWS_S3_BUCKET_ORIGINAL"),
compressed_bucket: System.get_env("AWS_S3_BUCKET_COMPRESSED"),
request_config_override: %{}
access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY"),
region: System.get_env("AWS_REGION"),
original_bucket: System.get_env("AWS_S3_BUCKET_ORIGINAL"),
compressed_bucket: System.get_env("AWS_S3_BUCKET_COMPRESSED"),
request_config_override: %{}
end
13 changes: 7 additions & 6 deletions lib/app/upload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ defmodule App.Upload do
import SweetXml
require Logger

@original_bucket Application.compile_env(:ex_aws, :original_bucket)
@compressed_bucket Application.compile_env(:ex_aws, :compressed_bucket)
@compressed_baseurl "https://s3.eu-west-3.amazonaws.com/#{@compressed_bucket}/"

@doc """
`upload/1` receives an `image` with the format
%{
Expand Down Expand Up @@ -48,8 +44,13 @@ defmodule App.Upload do
# Fetch the contents of the returned XML string from `ex_aws`.
# This XML is parsed with `sweet_xml`:
# github.com/kbrw/sweet_xml#the-x-sigil
#
# Fetching the URL of the returned file.
url = upload_response_body.body |> xpath(~x"//text()") |> List.to_string()
compressed_url = "#{@compressed_baseurl}#{file_name}"

# Creating the compressed URL to return as well
compressed_bucket_baseurl = "https://s3.eu-west-3.amazonaws.com/#{Application.get_env(:ex_aws, :compressed_bucket)}/"
nelsonic marked this conversation as resolved.
Show resolved Hide resolved
compressed_url = "#{compressed_bucket_baseurl}#{file_name}"
{:ok, %{url: url, compressed_url: compressed_url}}
else
{:error, reason} -> {:error, reason}
Expand All @@ -67,7 +68,7 @@ defmodule App.Upload do
{:ok, upload_response_body} =
image.path
|> ExAws.S3.Upload.stream_file()
|> ExAws.S3.upload(@original_bucket, file_name,
|> ExAws.S3.upload(Application.get_env(:ex_aws, :original_bucket), file_name,
acl: :public_read,
content_type: image.content_type
)
Expand Down