Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7225ed6
added deploy-sbx.yaml workflow
Jan 19, 2023
47b9a5c
added tf_state_bucket in deploy-sbx.yaml workflow
Jan 19, 2023
6665087
added tf_state_bucket in deploy-sbx.yaml workflow
Jan 19, 2023
afea8cb
added tf_state_bucket in deploy-sbx.yaml workflow
Jan 19, 2023
8641bcb
added tf_state_bucket in deploy-sbx.yaml workflow
Jan 20, 2023
8e800da
updated deploy-sbx.yaml workflow
Jan 21, 2023
61286f0
tear down the stack
mickmcgrath13 Jan 24, 2023
b63039a
use new enable_postgres flag
mickmcgrath13 Jan 24, 2023
184de98
specify subnets for postgres
mickmcgrath13 Jan 25, 2023
7da17a2
use database
mickmcgrath13 Jan 31, 2023
59e3066
try async function
mickmcgrath13 Jan 31, 2023
cf3a52e
debugging app startup
mickmcgrath13 Jan 31, 2023
fde57b4
remove postgres specific vars
mickmcgrath13 Jan 31, 2023
70da7b0
enable postgres code
mickmcgrath13 Jan 31, 2023
e175bc5
adjust output
mickmcgrath13 Jan 31, 2023
8054ab7
dedicated url for postgres
mickmcgrath13 Feb 1, 2023
670f6dc
include connection to pg client
mickmcgrath13 Feb 1, 2023
2b41d12
destroy the stack
mickmcgrath13 Feb 1, 2023
c6a27b6
recreate
mickmcgrath13 Feb 1, 2023
4edaa54
configure client in JS
mickmcgrath13 Feb 1, 2023
6201050
use dot notation for app
mickmcgrath13 Feb 1, 2023
a7d3643
add debugging for pg info and specify db for pg client
mickmcgrath13 Feb 1, 2023
272cc0e
force ssl
mickmcgrath13 Feb 1, 2023
7166491
use constring connection approach
mickmcgrath13 Feb 1, 2023
212b22b
fix syntax error
mickmcgrath13 Feb 1, 2023
a1a421f
fix pgdatabase reference in constring
mickmcgrath13 Feb 1, 2023
0035946
switch back to ssl
mickmcgrath13 Feb 1, 2023
a8e865e
move client connection to postgres endpoint and specify sql response
mickmcgrath13 Feb 1, 2023
c666e68
do not specify subnets
mickmcgrath13 Feb 1, 2023
b537b5c
specify subnets
mickmcgrath13 Feb 2, 2023
0ee84d8
do not specify subnets
mickmcgrath13 Feb 2, 2023
06a0b79
Destroy stack
LeoDiazL Feb 7, 2023
a78c6f2
Recreating stack - postgres disabled
LeoDiazL Feb 7, 2023
9b4d1d6
Enable postgres
LeoDiazL Feb 7, 2023
0ad34ec
Testing db_port change
LeoDiazL Feb 7, 2023
57fb856
Moved port back to default
LeoDiazL Feb 9, 2023
fbb8d8a
Changing port
LeoDiazL Feb 9, 2023
82cda25
Destroying
LeoDiazL Feb 21, 2023
a164424
recreating
LeoDiazL Feb 21, 2023
10a6486
re-destroying
LeoDiazL Feb 21, 2023
06bf325
testing
LeoDiazL Mar 9, 2023
9818e2a
Destroy
LeoDiazL Mar 9, 2023
5e76523
Update deploy-sbx.yaml
LeoDiazL Sep 29, 2023
5682395
Update deploy-sbx.yaml
LeoDiazL Sep 29, 2023
75c6649
Update deploy-sbx.yaml
LeoDiazL Sep 29, 2023
4763bdf
Update deploy-sbx.yaml
LeoDiazL Sep 29, 2023
3211585
Update deploy-sbx.yaml
LeoDiazL Nov 17, 2023
c69a98a
Update deploy-sbx.yaml
LeoDiazL Nov 17, 2023
9c707ed
Update deploy-sbx.yaml
LeoDiazL Nov 17, 2023
16169ff
Update deploy-sbx.yaml
LeoDiazL Nov 17, 2023
eb03115
Update deploy-sbx.yaml
LeoDiazL Nov 17, 2023
3ac44f2
Update deploy-sbx.yaml
LeoDiazL Nov 17, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
jobs:
EC2-Deploy:
# if the branch name of the PR does not contain 'skip-deploy'
if: "!contains(github.head_ref, 'skip-deploy')"
if: "!contains(github.head_ref, 'skip-deploy') && !contains(github.head_ref, 'rds')"
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/deploy-sbx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy-SBX

on:
push:
branches: [ feat/sbox-rds ]

permissions:
contents: read

jobs:
EC2-Deploy:
# if the branch name of the PR does not contain 'skip-deploy'
if: "!contains(github.head_ref, 'skip-deploy')"
runs-on: ubuntu-latest

steps:
- id: deploy
name: Deploy
uses: bitovi/github-actions-deploy-docker-to-ec2@main
with:
###
### App config
###

###
### AWS config
###
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_SANDBOX}}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_SANDBOX}}
aws_default_region: us-east-1

###
### Deployment config
###
# Provide a secret called `DOT_ENV` to append environment variables to the .env file
# dot_env: ${{ secrets.DOT_ENV }}
tf_stack_destroy: true
tf_state_bucket_destroy: true
tf_state_bucket: bitovi-devops-training-ec2-gha-example-feat-sbox-rds-tf-state
tf_state_file_name: tf-state

#aws_mount_efs_id: fs-089a6338a687599fc
###
### Postgres config
###
# postgres_subnets: "subnet-0f1b65df74adf6e87,subnet-05d768eabcd7591ea,subnet-082c8c6a0f81405d3"
#enable_postgres: true

# TODO:
# postgres_vpc_id = "vpc-081abe910edab4281"
# postgres_vpc_cidr = "172.31.0.0/16"
#postgres_database_port: 5444

23 changes: 22 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,28 @@ services:

# Specify a .env file for credentials
# the `AWS_INSTANCE_URL` environment variable will be prepended to that file
# env_file: .env
# if `enable_postgres` is set to `true`, the env file will also have the following
# ==== Postgres ====
# # Amazon Resource Name (ARN) of cluster
# POSTGRES_CLUSTER_ARN
# # Writer endpoint for the cluster
# POSTGRES_CLUSTER_ENDPOINT
# # A read-only endpoint for the cluster, automatically load-balanced across replicas
# POSTGRES_CLUSTER_READER_ENDPOINT
# # The running version of the cluster database
# POSTGRES_CLUSTER_ENGINE_VERSION_ACTUAL
# # Name for an automatically created database on cluster creation
# # database_name is not set on `aws_rds_cluster` resource if it was not specified, so can't be used in output
# POSTGRES_CLUSTER_DATABASE_NAME
# # The database port
# POSTGRES_CLUSTER_PORT
# # The database master password
# POSTGRES_CLUSTER_MASTER_PASSWORD
# # The database master username
# POSTGRES_CLUSTER_MASTER_USERNAME
# # The Route53 Hosted Zone ID of the endpoint
# POSTGRES_CLUSTER_HOSTED_ZONE_ID
env_file: .env

volumes:
- .:/app
Expand Down
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
var port = process.env.PORT || 3000;
var express = require('express');
var fs = require('fs');
var app = express();
const { Pool, Client } = require('pg')

app.get('/', function (req, res) {
res.send("Hello Bitovi Meetup - github-actions-deploy-docker-to-ec2");
app.get('/', async function (req, res) {
console.log("received request", req.route.path);
res.send(`Hello Bitovi Meetup - github-actions-deploy-docker-to-ec2`)
});
app.get('/postgres', async function (req, res) {
console.log("received request", req.route.path);

const client = new Client({
host: process.env.PGHOST,
port: process.env.PGPORT,
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PGDATABASE,
ssl: {
ca: fs.readFileSync('rds-combined-ca-bundle.pem').toString()
}
});
client.connect()
const result = await client.query('SELECT NOW()');
await client.end();


res.send(`Hello SQL timestamp: ${result.rows[0].now}`);
});

app.listen( port, function () {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"start": "node index.js"
},
"dependencies": {
"express": "^4.13.4"
"express": "^4.13.4",
"pg": "^8.9.0"
}
}