-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from o0th/midnacoin
kubernetes deployment
- Loading branch information
Showing
16 changed files
with
254 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
npm-debug.log | ||
|
||
.env | ||
|
||
infra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: midnabot | ||
|
||
on: | ||
release: | ||
types: | ||
- created | ||
|
||
jobs: | ||
docker: | ||
name: Docker | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up version | ||
id: version | ||
uses: martinbeentjes/npm-get-version-action@master | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Docker login | ||
run: | | ||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login \ | ||
--username ${{ secrets.DOCKER_USERNAME }} \ | ||
--password-stdin ${{ secrets.DOCKER_REPOSITORY }} | ||
- name: Docker build and push | ||
run: | | ||
docker buildx build \ | ||
--platform linux/arm64 \ | ||
--tag ${{ secrets.DOCKER_REPOSITORY }}/midnabot:${{ steps.version.outputs.current-version }} \ | ||
--build-arg SERVICE_PORT=${{ secrets.SERVICE_PORT }} \ | ||
--push . | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
node_modules | ||
|
||
*terraform* | ||
*.tfvars | ||
.terraform | ||
|
||
.env | ||
init.sh | ||
|
||
infra/secrets/* | ||
!infra/secrets/*.age |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM node:16-alpine | ||
|
||
ARG SERVICE_PORT | ||
ENV SERVICE_PORT=${SERVICE_PORT} | ||
|
||
EXPOSE ${SERVICE_PORT} | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
COPY . . | ||
|
||
CMD ["node", "index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
provider "kubernetes" { | ||
config_path = "~/.kube/config" | ||
} | ||
|
||
resource "kubernetes_namespace" "this" { | ||
metadata { | ||
name = "midnabot" | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "this" { | ||
metadata { | ||
name = "midnabot" | ||
namespace = kubernetes_namespace.this.metadata[0].name | ||
} | ||
|
||
type = "kubernetes.io/dockerconfigjson" | ||
|
||
data = { | ||
".dockerconfigjson" = file("${path.module}/secrets/docker-registry.json") | ||
} | ||
} | ||
|
||
resource "kubernetes_deployment" "this" { | ||
metadata { | ||
name = "midnabot" | ||
namespace = kubernetes_namespace.this.metadata[0].name | ||
} | ||
|
||
spec { | ||
replicas = 1 | ||
|
||
selector { | ||
match_labels = { | ||
"app" = "midnabot" | ||
} | ||
} | ||
|
||
template { | ||
metadata { | ||
labels = { | ||
"app" = "midnabot" | ||
} | ||
} | ||
|
||
spec { | ||
container { | ||
name = "midnabot" | ||
image = var.image | ||
|
||
image_pull_policy = "Always" | ||
|
||
env { | ||
name = "NODE_ENV" | ||
value = var.node_env | ||
} | ||
|
||
env { | ||
name = "SERVICE_PORT" | ||
value = var.service_port | ||
} | ||
|
||
env { | ||
name = "SERVICE_URL" | ||
value = var.service_url | ||
} | ||
|
||
env { | ||
name = "TELEGRAM_TOKEN" | ||
value = var.telegram_token | ||
} | ||
|
||
port { | ||
name = "https" | ||
container_port = var.service_port | ||
} | ||
} | ||
|
||
image_pull_secrets { | ||
name = kubernetes_secret.this.metadata[0].name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_service" "this" { | ||
metadata { | ||
name = "midnabot" | ||
namespace = kubernetes_namespace.this.metadata[0].name | ||
|
||
labels = { | ||
"app" = "midnabot" | ||
} | ||
} | ||
|
||
spec { | ||
selector = { | ||
"app" = "midnabot" | ||
} | ||
|
||
port { | ||
name = "https" | ||
port = var.service_port | ||
} | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "cert" { | ||
metadata { | ||
name = "cert" | ||
namespace = kubernetes_namespace.this.metadata[0].name | ||
} | ||
|
||
type = "kubernetes.io/tls" | ||
|
||
data = { | ||
"tls.crt" = file("${path.module}/secrets/tls.crt") | ||
"tls.key" = file("${path.module}/secrets/tls.key") | ||
} | ||
} | ||
|
||
resource "kubernetes_ingress" "this" { | ||
wait_for_load_balancer = true | ||
|
||
metadata { | ||
name = "midnabot" | ||
namespace = kubernetes_namespace.this.metadata[0].name | ||
annotations = { | ||
"kubernetes.io/ingress.class" = "public" | ||
"nginx.ingress.kubernetes.io/proxy-body-size" = "1024m" | ||
} | ||
} | ||
|
||
spec { | ||
tls { | ||
hosts = ["midnabot.o0th.io"] | ||
secret_name = kubernetes_secret.cert.metadata[0].name | ||
} | ||
|
||
rule { | ||
host = "midnabot.o0th.io" | ||
http { | ||
path { | ||
path = "/" | ||
backend { | ||
service_name = "midnabot" | ||
service_port = var.service_port | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
variable "service_url" { | ||
type = string | ||
} | ||
|
||
variable "service_port" { | ||
type = number | ||
} | ||
|
||
variable "node_env" { | ||
type = string | ||
} | ||
|
||
variable "telegram_token" { | ||
type = string | ||
} | ||
|
||
variable "image" { | ||
type = string | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.