Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: publish_image

on:
push:
branches:
- "master"

jobs:
docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: downcase GITHUB_REPOSITORY
run: |
echo "GITHUB_REPOSITORY_LOWERCASE=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ env.GITHUB_REPOSITORY_LOWERCASE }}:latest
ghcr.io/${{ env.GITHUB_REPOSITORY_LOWERCASE }}:1.0.1
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,38 @@ Temporary Items
docker-compose.yml
.env
dist

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"hashicorp.terraform",
"pkief.material-icon-theme"
]
}

15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files.eol": "\n",
"[terraform]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
},
"[terraform-vars]": {
"editor.defaultFormatter": "hashicorp.terraform",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
},
"workbench.iconTheme": "material-icon-theme"
}

22 changes: 19 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
FROM node:12-alpine
# Build stage
FROM node:12-alpine AS builder

WORKDIR /usr/src/app

COPY package.json .
COPY package*.json ./

RUN npm install --quiet

COPY . .

CMD ["npm", "run", "start"]
RUN npm run build

# Production stage
FROM node:12-alpine

WORKDIR /usr/src/app

COPY package*.json ./

# Install only production dependencies
RUN npm ci --only=production

# Copy built app from the previous stage
COPY --from=builder /usr/src/app/dist ./dist

CMD ["npm", "run", "start:prod"]
31 changes: 31 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3.8"

services:
web:
image: ghcr.io/juanmanuelgg/backvynils:latest
environment:
DB_HOST: "db"
ports:
- "3000:3000"
depends_on:
- db
links:
- db
networks:
- default

db:
image: postgres
environment:
- POSTGRES_DB=vinyls
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- default

volumes:
pgdata:
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ version: "3.8"
services:
web:
build: .
command: npm run start
volumes:
- /usr/src/app
environment:
DB_HOST: "db"
ports:
Expand All @@ -23,7 +20,12 @@ services:
- POSTGRES_DB=vinyls
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- default

volumes:
pgdata:
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { AlbumMusicianModule } from './albummusician/albummusician.module';
password: 'postgres',
database: 'vinyls',
entities: [Album, CollectorAlbum, Band, Collector, Comment, Musician, Performer, PerformerPrize, Prize, Track,],
dropSchema: true,
dropSchema: false,
synchronize: true,
keepConnectionAlive: true,
migrations: [__dirname + '/migration/**/*{.ts,.js}'],
Expand Down
26 changes: 26 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions terraform/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# This script is used to run terraform commands
terraform init
terraform destroy
terraform apply
24 changes: 24 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "foundation" {
source = "./modules/foundation"
do_token = var.do_token
region = var.region
domain = var.domain
do_ssh_pub_key_file = var.do_ssh_pub_key_file
}

module "vm" {
source = "./modules/vm"
do_token = var.do_token
region = var.region
digitalocean_ssh_key_id = module.foundation.digitalocean_ssh_key_id
vpc_uuid = module.foundation.vpc_uuid
ip_address = module.foundation.ip_address
proyect_id = module.foundation.proyect_id
}


module "firewall" {
source = "./modules/firewall"
do_token = var.do_token
droplet_id = module.vm.droplet_id
}
57 changes: 57 additions & 0 deletions terraform/modules/firewall/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
resource "digitalocean_firewall" "web" {
name = "web-22-53-80-443"

droplet_ids = [var.droplet_id]

inbound_rule {
protocol = "tcp"
port_range = "22"
source_addresses = ["0.0.0.0/0", "::/0"]
}
/* La idea es quitar http cuando ya se tiene https.
inbound_rule {
protocol = "tcp"
port_range = "80"
source_addresses = ["0.0.0.0/0", "::/0"]
}
*/
inbound_rule {
protocol = "tcp"
port_range = "443"
source_addresses = ["0.0.0.0/0", "::/0"]
}
/* Solo para pruebas
inbound_rule {
protocol = "tcp"
port_range = "3000"
source_addresses = ["0.0.0.0/0", "::/0"]
}
*/
outbound_rule {
protocol = "tcp"
port_range = "53"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
outbound_rule {
protocol = "udp"
port_range = "53"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
outbound_rule {
protocol = "tcp"
port_range = "80"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
outbound_rule {
protocol = "tcp"
port_range = "443"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
/* Solo para pruebas
outbound_rule {
protocol = "tcp"
port_range = "3000"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
*/
}
12 changes: 12 additions & 0 deletions terraform/modules/firewall/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.do_token
}
9 changes: 9 additions & 0 deletions terraform/modules/firewall/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "do_token" {
description = "DigitalOcean API token"
type = string
}

variable "droplet_id" {
description = "The ID of the droplet to apply the firewall to"
type = number
}
34 changes: 34 additions & 0 deletions terraform/modules/foundation/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
resource "digitalocean_ssh_key" "default" {
name = "SSH-DigitalOcean-key"
public_key = file(var.do_ssh_pub_key_file)
}

resource "digitalocean_vpc" "default" {
name = "my-network"
region = var.region
ip_range = "10.10.11.0/24"
}

resource "digitalocean_reserved_ip" "default" {
region = var.region
}

resource "digitalocean_domain" "default" {
name = var.domain
ip_address = digitalocean_reserved_ip.default.ip_address
}

resource "digitalocean_record" "www" {
domain = digitalocean_domain.default.id
type = "A"
name = "www"
value = digitalocean_reserved_ip.default.ip_address
}

resource "digitalocean_project" "default" {
name = "AppBajoPruebas"
description = "Un proyecto web del curso: Ingenieria de software para aplicaciones moviles."
purpose = "Web Application"
environment = "Development"
resources = [digitalocean_domain.default.urn]
}
15 changes: 15 additions & 0 deletions terraform/modules/foundation/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
output "digitalocean_ssh_key_id" {
value = digitalocean_ssh_key.default.id
}

output "vpc_uuid" {
value = digitalocean_vpc.default.id
}

output "ip_address" {
value = digitalocean_reserved_ip.default.ip_address
}

output "proyect_id" {
value = digitalocean_project.default.id
}
Loading