Ops
Search…
Introduction
Getting Started
Basic Usage
Configuration
Examples
Images
Instances
Volumes
Networking
Packages
Klibs
Hardware Acceleration
Google Cloud Integration
Azure
AWS
OpenStack
Digital Ocean
Vultr
VSphere
WorkStation
ProxMox
Hyper-V
Bhyve
Firecracker
UpCloud
Virtual Box
OCI
Visual Studio Code Extension
Terraform
Kubernetes
Bare Metal
Integrations
Debugging
CrossBuilding
Deploy
FAQ
Developer
Getting Started
Install from Source
Powered By
GitBook
Examples
Deploying a Static File Server
Lets start with a basic go static file server, copy-and-paste below to
server.go
:
1
package
main
2
3
import
(
4
"log"
5
"net/http"
6
)
7
8
func
main
()
{
9
fs
:=
http
.
FileServer
(
http
.
Dir
(
"static"
))
10
http
.
Handle
(
"/"
,
fs
)
11
12
log
.
Println
(
"Listening...on 8080"
)
13
http
.
ListenAndServe
(
":8080"
,
nil
)
14
}
Copied!
Now build
server.go
:
1
$
GOOS
=
linux go build server.go
Copied!
Prepare the HTML content:
1
$
mkdir
static
2
$
cd
static
Copied!
Create
hello.html
:
1
<!
doctype
html
>
2
<
html
>
3
<
head
>
4
<
meta
charset
=
"
utf-8
"
>
5
<
title
>
A static page
</
title
>
6
</
head
>
7
<
body
>
8
<
h1
>
Hello from a static page
</
h1
>
9
</
body
>
10
</
html
>
Copied!
Create a config file named
config.json
:
1
{
2
"Dirs"
:
[
"static"
],
3
"Files"
:
[
"/lib/x86_64-linux-gnu/libnss_dns.so.2"
,
"/etc/ssl/certs/ca-certificates.crt"
]
4
}
Copied!
If you are on linux you can use the above example to enable dns/tls, otherwise you can use this for local Mac examples.
Note:
This is more than likely to change in the very near future.
1
{
2
"Dirs"
:
[
"static"
]
3
}
Copied!
The directory structure should look like below after these steps:
1
.
2
├── config.json
3
├── server
4
└── static
5
└── hello.html
Copied!
Package and deploy:
1
$ ops run -p
8080
-c config.json server
Copied!
Notice that we are using KVM user-mode networking and have to forward host port 8080 to VM.
Curl it:
1
curl
http://localhost:8080/hello.html
Copied!
To learn more about various config options visit
OPS GitHub repository
. More examples can be found from the
ops-examples
repository
.
Previous
Configuration
Next
Images
Last modified
1yr ago
Copy link