Skip to content

Commit

Permalink
Digital Ocean setup + Docker optimization (arriven#142)
Browse files Browse the repository at this point in the history
* Fix some misspells and misslinks

* Add DO docs

* Remove redundant layers

* Compact dockerfile
  • Loading branch information
Amet13 authored Mar 5, 2022
1 parent 074b646 commit 3d7a840
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ config.json

# terraform
**/.terraform*
**/terraform.tfvars
**/terraform.tfstate*

.history
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ FROM alpine:3.11.3 as openvpn
RUN apk add --update supervisor openvpn curl && rm -rf /tmp/* /var/cache/apk/*

ADD supervisord/supervisord.conf /etc/
ADD supervisord/supervisord-openvpn.conf /etc/supervisor/conf.d/
ADD supervisord/supervisord-db1000n.conf /etc/supervisor/conf.d/
ADD run/openvpn-up.sh run/run-openvpn.sh run/db1000n.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/openvpn-up.sh
RUN chmod +x /usr/local/bin/run-openvpn.sh
RUN chmod +x /usr/local/bin/db1000n.sh
ADD supervisord/supervisord-openvpn.conf \
supervisord/supervisord-db1000n.conf /etc/supervisor/conf.d/
ADD run/openvpn-up.sh \
run/run-openvpn.sh \
run/db1000n.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/openvpn-up.sh \
/usr/local/bin/run-openvpn.sh \
/usr/local/bin/db1000n.sh

WORKDIR /usr/src/app
COPY --from=builder /build/main .
Expand Down
29 changes: 29 additions & 0 deletions terraform/digital_ocean/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Digital Ocean deployment

## Requirements

- Digital Ocean account
- API token (Go to API - Personal access tokens) and generate Personal access token (with write permissions)
- `terraform` (1.0+) installed

## Deploy

To deploy run:

```terraform
export DO_TOKEN=<place-api-token-here>
terraforim init
terraform plan -var "do_token=${DO_TOKEN}"
terraform apply -var "do_token=${DO_TOKEN}"
```

After deployment (usually takes 5-10 mins) go to [Apps List](https://cloud.digitalocean.com/apps), find an app with name `db1000n` and chek Runtime Logs.

## Destroy

To destroy infrastructure use commands:

```terraform
export DO_TOKEN=<place-api-token-here>
terraform destroy -var "do_token=${DO_TOKEN}"
```
18 changes: 18 additions & 0 deletions terraform/digital_ocean/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "digitalocean_app" "db1000n" {
spec {
name = "db1000n"
region = var.region

worker {
name = "db1000n-service"
environment_slug = "go"
instance_count = var.instance_count
instance_size_slug = var.instance_size_slug

git {
repo_clone_url = var.repo
branch = "main"
}
}
}
}
13 changes: 13 additions & 0 deletions terraform/digital_ocean/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
required_version = "~> 1.0"
}

provider "digitalocean" {
token = var.do_token
}
3 changes: 3 additions & 0 deletions terraform/digital_ocean/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instance_count = 1
instance_size_slug = "professional-xs"
region = "nyc"
25 changes: 25 additions & 0 deletions terraform/digital_ocean/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "do_token" {
type = string
}

variable "repo" {
type = string
default = "https://github.com/Arriven/db1000n"
}

variable "instance_count" {
type = number
default = 1
}

# https://docs.digitalocean.com/reference/api/api-reference/#operation/list_instance_sizes
variable "instance_size_slug" {
type = string
default = "professional-xs"
}

# https://docs.digitalocean.com/reference/api/api-reference/#operation/list_all_regions
variable "region" {
type = string
default = "nyc1"
}

0 comments on commit 3d7a840

Please sign in to comment.