mirror of https://github.com/mitchell/shortnr.git
Add terraform configuration; Modify dockerfile workdirs;
Modify router to simplify routes
This commit is contained in:
parent
fa5f55740c
commit
7ea55a00f3
|
@ -27,3 +27,9 @@ service-*.tar
|
||||||
|
|
||||||
# Ignore development DETS file
|
# Ignore development DETS file
|
||||||
urls
|
urls
|
||||||
|
|
||||||
|
# Terraform related files
|
||||||
|
*.tfstate
|
||||||
|
*.tfstate.backup
|
||||||
|
*.tfvars
|
||||||
|
.terraform/
|
||||||
|
|
12
Dockerfile
12
Dockerfile
|
@ -1,17 +1,19 @@
|
||||||
FROM elixir:1.10 as build
|
FROM elixir:1.10 as build
|
||||||
|
|
||||||
WORKDIR /root/shortnr
|
WORKDIR /shortnr
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN mix local.hex --force
|
RUN mix local.hex --force
|
||||||
RUN mix local.rebar --force
|
RUN mix local.rebar --force
|
||||||
|
|
||||||
RUN env MIX_ENV=prod mix release
|
ENV MIX_ENV prod
|
||||||
|
RUN mix clean --deps
|
||||||
|
RUN mix release
|
||||||
|
|
||||||
FROM debian:stable-20191224-slim
|
FROM debian:stable-20191224-slim
|
||||||
|
|
||||||
WORKDIR /home/shortnr
|
WORKDIR /shortnr
|
||||||
COPY --from=build /root/shortnr/_build/prod/rel/shortnr/ .
|
COPY --from=build /shortnr/_build/prod/rel/shortnr/ .
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
libtinfo5=6.1+20181013-2+deb10u2 \
|
libtinfo5=6.1+20181013-2+deb10u2 \
|
||||||
|
@ -26,7 +28,7 @@ ENV LANGUAGE en_US:en
|
||||||
ENV LC_ALL en_US.UTF-8
|
ENV LC_ALL en_US.UTF-8
|
||||||
|
|
||||||
RUN groupadd -r shortnr && useradd --no-log-init -r -g shortnr shortnr
|
RUN groupadd -r shortnr && useradd --no-log-init -r -g shortnr shortnr
|
||||||
RUN chown -R shortnr:shortnr /home/shortnr
|
RUN chown -R shortnr:shortnr /shortnr
|
||||||
USER shortnr
|
USER shortnr
|
||||||
|
|
||||||
ENTRYPOINT ["bin/shortnr", "start"]
|
ENTRYPOINT ["bin/shortnr", "start"]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
FROM elixir:1.10 as dev
|
FROM elixir:1.10 as dev
|
||||||
|
|
||||||
WORKDIR /root/shortnr
|
WORKDIR /shortnr
|
||||||
|
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
RUN apt-get install -y fish vim
|
RUN apt-get install -y fish vim rsync
|
||||||
|
|
||||||
RUN mix local.hex --force
|
RUN mix local.hex --force
|
||||||
RUN mix local.rebar --force
|
RUN mix local.rebar --force
|
||||||
|
|
|
@ -16,13 +16,13 @@ defmodule Shortnr.Router do
|
||||||
plug(:dispatch)
|
plug(:dispatch)
|
||||||
|
|
||||||
# BEGIN URL routes
|
# BEGIN URL routes
|
||||||
post("/urls/:url", do: URL.Endpoints.select(conn, :create, url))
|
post("/:url", do: URL.Endpoints.select(conn, :create, url))
|
||||||
|
|
||||||
get("/", do: URL.Endpoints.select(conn, :list))
|
get("/", do: URL.Endpoints.select(conn, :list))
|
||||||
get("/urls", do: URL.Endpoints.select(conn, :list))
|
|
||||||
get("/:id", do: URL.Endpoints.select(conn, :get, id))
|
get("/:id", do: URL.Endpoints.select(conn, :get, id))
|
||||||
|
|
||||||
delete("/:id", do: URL.Endpoints.select(conn, :delete, id))
|
delete("/:id", do: URL.Endpoints.select(conn, :delete, id))
|
||||||
|
|
||||||
# END
|
# END
|
||||||
|
|
||||||
match _ do
|
match _ do
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
# vim:foldmethod=indent
|
||||||
|
|
||||||
|
provider "google" {
|
||||||
|
version = "3.8.0"
|
||||||
|
project = var.project_id
|
||||||
|
region = "us-east4"
|
||||||
|
zone = "us-east4-b"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_keys" {
|
||||||
|
type = string
|
||||||
|
description = "The ssh username and key in the format `username:ssh-key`."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "project_id" {
|
||||||
|
type = string
|
||||||
|
description = "The name of the google cloud project you're deploying to."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "deletion_protection" {
|
||||||
|
type = bool
|
||||||
|
description = "Whether to apply deletion protection to the shortnr-instance."
|
||||||
|
default = true
|
||||||
|
}
|
||||||
|
|
||||||
|
output "shortnr_static_ip" {
|
||||||
|
value = google_compute_address.selfpass.address
|
||||||
|
description = "The public static IP address used by the Shortnr instance."
|
||||||
|
}
|
||||||
|
|
||||||
|
data "google_compute_image" "debian_image" {
|
||||||
|
family = "debian-10"
|
||||||
|
project = "debian-cloud"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_address" "selfpass" {
|
||||||
|
name = "selfpass-address"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "selfpass" {
|
||||||
|
name = "selfpass-instance"
|
||||||
|
machine_type = "f1-micro"
|
||||||
|
deletion_protection = var.deletion_protection
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
auto_delete = false
|
||||||
|
|
||||||
|
initialize_params {
|
||||||
|
image = data.google_compute_image.debian_image.self_link
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = "default"
|
||||||
|
access_config {
|
||||||
|
nat_ip = google_compute_address.selfpass.address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
ssh-keys = var.ssh_keys
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "http_server" {
|
||||||
|
name = "http-server"
|
||||||
|
network = "default"
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["80"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "docker_machine" {
|
||||||
|
name = "docker-machine"
|
||||||
|
network = "default"
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["2376"]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue