A podcast about using Elm coming from Javascript and other languages
For a match to succeed, the LHS and RHS must have the same shape, and each value on the right must match the corresponding value on the left. If the thing on the left is an unbound variable, Elixir binds that variable to the value being matched.
JavaScript to Elm
Jesse Tomchak
Need for distillery to run migrations on deploy
It's great that I had the command correct in the this write up.
Custom commands give you a lot of power to express potentially complex operations as a terse statement. I would encourage you to use them for these types of tasks rather than using the raw rpc and eval tasks!
App Engine to remove old instances
Force SSL
We are pretty bad at CSS. In a perpetual cycle kind of way. So we need to be better. This is definitely an area where we need to improve on.
build_assoc(struct, assoc, attributes \ %{}) Builds a struct from the given assoc in model.
If the relationship is a has_one or has_many and the key is set in the given model, the key will automatically be set in the built association / Ecto Documentation
def change do alter table("posts") do add: user_id, :uuid endWe want a profile page for users
The layout and details
Routes
Just do it already!
MB:postit> mix phx.gen.html Posting Post posts title:string content:text * creating lib/postit_web/controllers/post_controller.ex * creating lib/postit_web/templates/post/edit.html.eex * creating lib/postit_web/templates/post/form.html.eex * creating lib/postit_web/templates/post/index.html.eex * creating lib/postit_web/templates/post/new.html.eex * creating lib/postit_web/templates/post/show.html.eex * creating lib/postit_web/views/post_view.ex * creating test/postit_web/controllers/post_controller_test.exs * creating lib/postit/posting/post.ex * creating priv/repo/migrations/20190717045929_create_posts.exs * creating lib/postit/posting.ex * injecting lib/postit/posting.ex * creating test/postit/posting_test.exs * injecting test/postit/posting_test.exs Add the resource to your browser scope in lib/postit_web/router.ex: resources "/posts", PostController remember to update your repository by running migrations: $ mix ecto.migrate MB:postit>That didn't take long. Our first error. 😭
assign @current_user not available in eex template.we'd forgotten to add the security plug to get for auth and the conditional in our Navbar is looking for current_user in order to render the login or logout buttons. happy that was simple.
Create a controller helper and add it in here!
There are two types of plugs in the Phoenix. They are module plugs and function plugs. We are going to cover both of them in this article.
having stumbled into it in an effort to 'DRY' out our code. And really, there will probably be more controllers in our app over time and I feel like I have really hit the sweet spot of learning
What is the difference between alias and import ?
alias use shorter name instead of the fully qualified name or prefix
changeset
conn
defp
JavaScript to Elm
Jesse Tomchak
I have no desire to roll my own. While a lot can be learned from this type of exercise, it is not something I want to get hung up on. Plus it's a MONSTER subject. Not one to be taken lightly, so we'll outsource the safe keeping of user info and the authentication mechanics. So we can focus on the implementation of it.
Adding some event counter for sampling
mix phx.gen.html Events Event events title due:datetime I've never been a fan of generators like this before, but I am also tired of hand carving the same things over and over in my React apps. So I'm all in.
Add the resource to your browser scope in lib/postit_web/router.ex: resources "/events", EventController Remember to update your repository by running migrations: $ mix ecto.migrateSign up for auth0
Nothing beats debuging after typeing it out.
Create an auth controller
Remember what started us down the path of managing a kubernetes cluster in the first place? No, it wasn't our own sadistic desire to to devops in an effort to avoid building an actual project, but close. We want to be able to leverage 'live view' in our project, that requires websockets, which all signs pointed to not available on appengine. But wait, what's this? App-Enggine WebSocket Support As of Feb 2019, it looks like we're good to go. That coupled with the $30/month bill we would incur when our gcp credits ran out, this switch seems to make a lot of sense.
Clean upupdate KMS key/value on key for beta app. remember we tore everything down and needed to create a smaller db instance
run mix ecto.create to instantiate new db and mix ecto.migrate
we can see that the app in prod was able to connect and create the db by the right name in the gcp console.
so we've got a new connection name and db name. I left the others the same, so I didn't have to create all new keys for it.
Create app.yaml file
env: flex runtime: gs://elixir-runtime/elixir.yaml runtime_config: release_app: postit beta_settings: cloud_sql_instances: [CONNECTION-DB]and then just gcloud app deploy
but wait - had to remove the dockerfile and the cloudbuild from the directory so it would run
mmmm, no env's for database name or password?? grrrrr 😡
GenServer #PID<0.1713.0> terminating ** (RuntimeError) connect raised KeyError exception: key :database not found. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the detailsSo if we update the cloudbuild to publish the docker image we've been making to app deploy instead of kubectl, then it will have all the compile time variables from KMS in it and run from the could build instead of locally, right?
update docker and cloudbuild to use the newest KMS key's for database name and variables. printenv from the docker build to confirm.
do i need a custom start command?
enable App Engine Admin API 🤦♀️ you'd think i'd know that by now
change the sql directory to /cloudsql/[CONNECTION_NAME] that's just removing the tmp/ from our KMS. Which i can just update and replace the base64 string in the cloudbuild file. so that's rad.
At this point. For someone who is pretty vocal about not liking the devops side of things, you sure spend a lot of time working on those details.
Ok where'd we leave off?
And what'd we get for all that effort?
Follow
ipv6:
When to set config
AWS is a jungle
So.. I guess I need docker 🙄
GCP cloud_sql connection
Creating docker image
Can I test this image?
Debug in prod?
SQL Admin API access
Where'd PORT go?
Docker build is gonna need more RAM
Docker Args
GCP Secrets?
Google KMS (Cloud Key Management)
Loadbalance and HTTPS
The key thing here is to specify the type and your deployment's name. This will expose your deployment through a service and set up a Load Balancer on Google Cloud Platform.
Best Practices for deploying Elixir
Docker ENV passed with -build-arg
Follow
Problems with Postgres install and running
Add Distillery {:distillery, "~> 2.0"}
Hex Package Manager for the BEAM ecosystem
Hex was started as an open-source project early 2014, it is still an open-source project but today it is operated by the Swedish limited company "Six Colors AB". The company was founded in 2018 by the creator of Hex, Eric Meadows-Jönsson, Six Colors supports the development of Hex and operates all services required to run Hex.
By charging for private packages we can fund free open-source development and run reliable services for both paying customers and the open-source community.
Setup a VM on Azure
Setup the Postgres
Probably need to get the postgres creds into the prod build for my app?
npm run deploy --prefix assets && MIX_ENV=prod mix do phx.digest, release --env=prod
Let's try this without an Nginx proxy 🤷♀️
Getting the DB connection is a struggle
Let's go with the AWS option, and we're going to roughly follow a couple guides to get what we what. And what's that?
1. Continuous Deployment 1. Whatever I git commit to Master is built and deployed to the running instance. Whether that's a hot upgrade, or a deploy and drain of an EC2. Whatever, I'm not too concerned with the details at this point. I want to be able to build locally, test it out, and then trigger a deploy by doing what I already do, a git commit and / or merge 2. Wanta be able to rollback easily. That might be aws cli, or even a click on the aws console. Either would be fine, I have no idea how this will work in practice with automatic build and deploy yet. 3. Build fail if tests fail.
or this one Elixir w/ Docker on AWS
AWS install cli and get signed in.
Get the project up on git up
Create the RDS postgresql and get the address, username, and password,
Create an encrypted S3 bucket for secrets
Spin up 2 EC2 instances of the default linux and ssh into them with the *.pem that you download from the console
ssh into ec2 instance and install codedeploy mmmmmmm. with a list of 8 commands ?
That seemed to be the easy part. I've now got code deploy agent running on my instances, Now it appears I need an appspec.yaml oh boy do I love YAML files.
Current cycle:
Now on 8 failed deploys
Then it occurs to me. Even if I get it running.
So over to codebuild as a product.
Mess with codebuildfor a couple hours
Realize that pipeline is really what I want and that some options aren't available unless you start from there
Build a pipeline
detour from aws to CircleCI for another couple hours
Even within a project I will bounce when I hit a wall, rather than taking a 10 minute break and coming back to it. I was trying to be super good at time tracking, but it's gone out the window for this project.
Got it building and testing on CircleCI, then aws orbs showed up when I went to figure out how to get the build from the CI to S3 so finally get it to the EC2 instances to run
That seems like a real chore, using the same aws-cli that I was using in the aws interface !!!!
Back to aws 😭
At least there is gobs of documentations and help articles
Cool I like VPC (Virtual Private Cloud)
loadbalancers need 2 subnets in different available zones
both need to have an internet gateway ? which means the routing table for both public subnets created need to have internet gateway … i think
ok. got past that step. now
AWS Certificate Manager (ACM) is the preferred tool to provision and store server certificates. If you previously stored a server certificate using IAM, you can deploy it to your load balancer. Learn more about HTTPS listeners and certificate management.
so many steps
ok. so have a cert for the domain.
Use NameServe from aws to populate the 'nameserve' on hover.
Now. Now we can set up the loadbalancer with a target 'group'
Remember we need to actually deploy the code from S3 to the EC2.
Need to ssh in and install codedeploy again
had to swipe ec2 instances and start again
Need Blue/Green so 2 ? 🤷♀️
Also remember there is no codedeploy agent on the ec2's anymore
AND they are not publicly accessible so I can't ssh into them and run the commands
so that leads me to AWS System Manger 🤦♂️
The version of SSM Agent on the instance supports Session Manager, but the instance is not configured for use with AWS Systems Manager. Verify that the IAM instance profile attached to the instance includes the required permissions. Learn more
Elm In the Spring Videos are up LINK
I was gonna steer clear of this topic after initially reading the post by Chris Gregori Elm and why its not quite ready yet , and the follow up by Lucas Payr How Can the Elm Coummity Imporve , but it sort of festered on my mind, which listening to this reason behind this weeks tardy release. I have another episode in the cooker, one that was a lot more fun to work on, but there was something about this open conversation that I just can't shake.
There is no answer here, only those searching
That's my disclaimer.
SummaryI think both articles from Chris and Lucas where thoughtful, articulate and constructive. I didn't get any sense of trolling, flaming, or even so much as a hint of rudeness.
Chris wrote on article titled 'Elm and Why it's Not Quite Ready Yet' where he outlines several points that he believes makes Elm, as the title suggests, not ready for prime time. To be fair, he does list a fair amount of good points and things that he likes in the language too. What I'm trying to get at, it's more than just a fly by gripe list, which is why it stuck with me.
- Debugging looks awful and is largely unhelpful - You cannot install Elm packages from anywhere other than the official package repository. - Most of the tutorials / examples online are out of date due to v0.19 - The docs are incompleteElm core development lives in a walled garden that you can't touch, even if you wanted to - This one centers on the 'native code' ability removed in 0.19
Lacks the ecosystem of its siblings - refer to the 'awesome list'
So that's quite a list. And to be frank with you. I have had each and everyone of these thoughts at one time or another. I would venture to say it's a pretty accurate list. Now do they repel me from Elm? Not really, I'm still here sharing with you and trying to get better. But I do think about them from time to time.
Now the other reason I wanted to talk about this is because Lucas came up with, what I thought was a great perspective, it's not a bullet for bullet rebuttal, what would be the purpose of that? Convincing Chris that his opinion is wrong, that Elm is better than sliced bread, that he should feel bad for thinking such things? So many of the comments and rebuttals online are exactly this, "you're wrong and here's why". But as I noted, this is not what Lucas did, instead
What are problems in Elm that the community can solve? And how can we solve them?
He goes on to layout out community resource points, the news letters available, this very podcast ☺ and equally as awesome Elm Town, conferences, and ecosystem. It's a great list, I didn't even know about Elmfinder !!! Seriously look through this list Lucas put together, I am sure there is something on it you didn't know was out there.
Documentation
Good Practices Elm Cookbook
Conclusion
So now what? Head over to discourse and let's work on it, together.
ResourcesHow Can the Elm Community Improve
Elm and why its not quite ready yet
"The Hard Parts of Open Source" by Evan Czaplicki
FollowJavaScript to Elm
Jesse Tomchak
Covering the current state of open source support both monetarily and emotionally to those that put in so much work and effort that everyone benefits from.
Links
Actions is to contribute to the Gatsby project and Babel?
Let's start with becoming a contributor and go from there. By, say next week.
We set out this with a theme this year. Not a resolution, but an idea of something tangible that wanted to accomplish or do better in our efforts here. If you're not super familiar with themes, as I was not, I'd encourage you to listen to Cortex on Relay FM, of course they are in the show notes.
Cortex #79: 2019 Yearly Themes - Relay FM
Cortex #62: 2018 Yearly Themes - Relay FM
Actual Reddit thread gives a good rundown of yearly themes, but for me it's really something you can ask yourself when you're doing something, or you're looking at your to do list, or list of projects you want to work on. Whether those are side projects, or maybe they are part of your business in the case of Myke and Grey. (Those are the peeps from the show Cortex)
So what was my theme? Creating Content and Simple Automation. Episode #64 Aptly titled 'Themes' goes into both in pretty good detail, and I thought since it's nearly the 1/2 way point of the year, how am I doing?
The idea, whenever I start in on something overly complex or silly. I'm not looking for a Rube Goldberg machine, the exact opposite. I can think, "does this fit in my theme of create content with simple automation?" and if the answer is not a resounding YES then I can skip it.
Me from Episode #64Score card
Creating Content
Simple Automation
And this was a very powerful idea. I have dozens if not a hundred started projects. Notice that I said started. Not finished, not even abandoned. Just started.
I always have good intentions of coming back to a project, ignoring the others that I have yet to return to.
Me
Can't say I've enjoyed WordPress a lot. I understand more why people do like it. I've found a plugins for markdown, adding code snippets without having to make functions in the themes, that then get overridden when it inevitability needs to be updated. Which is a bit miserable when it's hosted on Cent OS with selinux turned on. 🤷♀️ But those are all things I know now.
Cortex #44: Existential Time Tracking
Elmstatic by Alex Korban
Model -> View -> Update
Custom Type is just a data structure in which to dispatch a function. Msg is not a function, but a custom type type. And the function update, takes a model, and a