Docker One Liners
Why install
- tags
- docker
I've been playing with OpenFaaS recently and it's a very accessable
way to starting building cloud first services. I wanted to see what I
could cram in there, so I built a few templates that would let me host
a static site. One that is just html, and another than can be built
with something like create-react-app
.
Create the template
directory:
|
|
Then add a template/static/template.yml
file:
|
|
Then add a template/static/Dockerfile
to do the build:
|
|
Setting up the Caddyfile
:
|
|
This will proxy /ui/*
, /system/*
, and /function/*
to the OpenFaaS
gateway, and everything else it will (internally) rewrite to
/function/static/
, which will get forwarded our static handler. So
when you deploy the function make sure you name it that!
First we need to create our template
directory:
|
|
First we need to create a template/react/template.yml
file
|
|
node_modules
, my least favorite thing in the world, needs to get
excluded, so lets create template/react/.dockerignore
. The react
here
must be the same as the handler_folder
above.
|
|
Then we add the Dockerfile
to build everything:
|
|
First we will create the function itself, and then populate it using
npx create-react-app testappreact
. This will write it into the "handler"
directory.
We will also remove the .git
repo that create-react-app
sets up.
|
|
I recommend using relative links, by adding "homepage": "./"
in the
generated package.json
file.
Then we can build and deploy using
|
|
And visit your server to see what you see!
Just for fun, lets make it build a vue app.
|
|
In order to get vue apps to have relative paths, you need to create a
vue.config.js
file to set it:
|
|
And since vue
builds in the dist
directory, we need to modify the
build script inside of package.json
to rename the file after it's
built:
|
|
Then, we can build and deploy:
|
|
It's a little hacky but it seems to work alright!
Previously
Next