Skip to content

Commit

Permalink
Make AWS run
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-makes committed Aug 5, 2022
1 parent 55d38ef commit 03530ad
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 37 deletions.
105 changes: 75 additions & 30 deletions .github/workflows/push_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,92 @@ env:
GO_VERSION: '1.18'
DOCKER_LOGIN_AVAILABLE: ${{ secrets.OHAI_DOCKER_HUB_ID }}

permissions:
id-token: write

jobs:
static-analysis:
name: Run all static analysis checks
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: newrelic/newrelic-infra-checkers@v1
- name: Semgrep
uses: returntocorp/semgrep-action@v1
with:
auditOn: push
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
continue-on-error: ${{ github.event_name != 'pull_request' }}
with:
only-new-issues: true
#static-analysis:
# name: Run all static analysis checks
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v2
# - uses: newrelic/newrelic-infra-checkers@v1
# - name: Semgrep
# uses: returntocorp/semgrep-action@v1
# with:
# auditOn: push
# - name: golangci-lint
# uses: golangci/golangci-lint-action@v2
# continue-on-error: ${{ github.event_name != 'pull_request' }}
# with:
# only-new-issues: true

test-nix:
name: Run unit tests on *Nix
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Checkout project's source code
uses: actions/checkout@v3
- name: Login to DockerHub
if: ${{env.DOCKER_LOGIN_AVAILABLE}}
uses: docker/login-action@v1
with:
username: ${{ secrets.OHAI_DOCKER_HUB_ID }}
password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }}
- name: Unit tests
run: make ci/test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: "arn:aws:iam::801306408012:role/role-assumable-by-github"
aws-region: us-east-2

test-build:
name: Test binary compilation for all platforms:arch
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
if: ${{env.DOCKER_LOGIN_AVAILABLE}}
uses: docker/login-action@v1
# - name: Unit tests
# run: make ci/test

- name: Provision an Oracle Instance
uses: newrelic/infrastructure-agent/.github/actions/external_runner@master
with:
username: ${{ secrets.OHAI_DOCKER_HUB_ID }}
password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }}
- name: Build all platforms:arch
run: make ci/build
aws_region: us-east-1
ecs_cluster_name: github-task-runner
task_definition_name: github-task--oracledb-e2e-tester
cloud_watch_logs_group_name: /ecs/github-task-runner
cloud_watch_logs_stream_name: ecs/provisioner
aws_vpc_subnet: subnet-07e919557ceb6ebeb
log_filters: ".*"
container_make_target: >-
--repository https://github.com/${{ github.repository }}
--ref ${{ github.head_ref }}
--
e2e/provision
TERRAFORM_WORKSPACE=ghrun-pr-${{ github.event.pull_request.number }}
- name: Deprovision the Oracle Instance
uses: newrelic/infrastructure-agent/.github/actions/external_runner@master
with:
aws_region: us-east-1
ecs_cluster_name: github-task-runner
task_definition_name: github-task--oracledb-e2e-tester
cloud_watch_logs_group_name: /ecs/github-task-runner
cloud_watch_logs_stream_name: ecs/provisioner
aws_vpc_subnet: subnet-07e919557ceb6ebeb
log_filters: ".*"
container_make_target: >-
--repository https://github.com/${{ github.repository }}
--ref ${{ github.head_ref }}
--
e2e/deprovision
TERRAFORM_WORKSPACE=ghrun-pr-${{ github.event.pull_request.number }}
#test-build:
# name: Test binary compilation for all platforms:arch
# runs-on: ubuntu-20.04
# steps:
# - uses: actions/checkout@v2
# - name: Login to DockerHub
# if: ${{env.DOCKER_LOGIN_AVAILABLE}}
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.OHAI_DOCKER_HUB_ID }}
# password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }}
# - name: Build all platforms:arch
# run: make ci/build

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NATIVEARCH := $(shell go version | awk -F '[ /]' '{print $$5}')
INTEGRATION := oracledb
BINARY_NAME = nri-$(INTEGRATION)
GO_FILES := ./src/
GOFLAGS = -mod=readonly
GOFLAGS = -mod=readonly

all: build

Expand Down Expand Up @@ -35,5 +35,6 @@ test:
# Include thematic Makefiles
include $(CURDIR)/build/ci.mk
include $(CURDIR)/build/release.mk
include $(CURDIR)/test/terraform_modules/provision.mk

.PHONY: all build clean compile test
10 changes: 10 additions & 0 deletions test/Dockerfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ghcr.io/oracle/oraclelinux8-instantclient:21

RUN curl -o /etc/yum.repos.d/newrelic-infra.repo https://download.newrelic.com/infrastructure_agent/linux/yum/el/8/x86_64/newrelic-infra.repo && \
dnf install -y dnf-plugins-core && \
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo && \
yum install -y make terraform

ADD entrypoint.sh /entrypoint.sh

ENTRYPOINT ["sh", "/entrypoint.sh"]
32 changes: 32 additions & 0 deletions test/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env sh
set -e

help() {
echo "This entrypoint limit users input to make targets but provides the possibility"
echo "to clone a repository before executing make. These are the accepted args:"
echo ""
echo "/entrypoint.sh [-v|--verbose] [-g|--github|--repository] [-r|--ref|--branch|--commit] [-h|--help] [--] <make target and variables>"
echo ""
echo " -v, --verbose Set shell's verbose mode"
echo " -g, --repository Set the repository's url from where to clone it"
echo " -r, --ref, --commit Set"
echo " -h, --help Set"
exit 1
}

while true; do
case "$1" in
-v | --verbose ) set -x; shift ;;
-g | --repository ) REPO="$2"; shift 2 ;;
-r | --ref | --commit ) REF="$2"; shift 2 ;;
-h | --help ) help ;;
-- ) shift; break ;;
* ) break ;;
esac
done

echo "Cloning '${REF}' reference from the repo '${REPO}'"
git clone "${REPO}" "${REF}"

echo Calling make "$@"
make "$@"

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

Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
resource aws_db_subnet_group oracle_db {
name = "oracle-db"
name = "oracle-db--${terraform.workspace}"
tags = {
from_github = length(regexall("ghrun-", terraform.workspace)) > 0 ? "yes" : "no"
workspace = terraform.workspace
}

subnet_ids = [
# If I use a random provider random numbers could collide so https://xkcd.com/221/
data.terraform_remote_state.base_framework.outputs.aws_network_private_subnets[0].id,
data.terraform_remote_state.base_framework.outputs.aws_network_private_subnets[1].id,
data.terraform_remote_state.base_framework.outputs.aws_network_private_subnets[5].id,
data.terraform_remote_state.base_framework.outputs.common_networking.aws_subnet.private_subnets[0].id,
data.terraform_remote_state.base_framework.outputs.common_networking.aws_subnet.private_subnets[1].id,
data.terraform_remote_state.base_framework.outputs.common_networking.aws_subnet.private_subnets[5].id,
]
}

resource aws_db_instance oracle_db {
tags = {
Name = "oracle-db--${terraform.workspace}"
from_github = length(regexall("ghrun-", terraform.workspace)) > 0 ? "yes" : "no"
workspace = terraform.workspace
}

# https://docs.aws.amazon.com/AmazonRDS/latest/OracleReleaseNotes/Welcome.html
engine = "oracle-ee"
engine_version = "19.0.0.0.ru-2021-10.rur-2021-10.r1"
engine_version = "19.0.0.0.ru-2022-01.rur-2022-01.r1"
# engine_version = "21.0.0.0.ru-2022-01.rur-2022-01.r1"

instance_class = "db.t3.small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ terraform {
backend s3 {
bucket = "nr-coreint-terraform-tfstates"
dynamodb_table = "nr-coreint-terraform-locking"
key = "base-framework/nri-oracledb.tfstate"
key = "integrations/oracledb/aws_managed_instance.tfstate"
region = "us-east-1"
profile = "base-framework"
}
Expand Down
22 changes: 22 additions & 0 deletions test/terraform_modules/fargate-task/.terraform.lock.hcl

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

33 changes: 33 additions & 0 deletions test/terraform_modules/fargate-task/github-runner.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource aws_ecs_task_definition oracledb_e2e_runner {
family = "github-task--oracledb-e2e-tester"

task_role_arn = data.terraform_remote_state.base_framework.outputs.github_runner.aws_iam_role.task_role.arn
execution_role_arn = data.terraform_remote_state.base_framework.outputs.github_runner.aws_iam_role.execution_role.arn
requires_compatibilities = ["FARGATE"]

cpu = 2 * 1024 # Measured in shares: 1024 shares == 1 vCPU
memory = 4 * 1024 # Measured in megabytes
network_mode = "awsvpc"

container_definitions = jsonencode([
{
name = "provisioner",
#cpu = 2 * 1024, # Measured in shares: 1024 shares == 1 vCPU
#memory = 4 * 1024, # Measured in megabytes

essential = true,
readonlyRootFilesystem = false,

image = "jperezflorez123/nri-oracledb:devel-tooling-latest",

logConfiguration = {
"logDriver" = "awslogs"
"options" = {
"awslogs-group" : data.terraform_remote_state.base_framework.outputs.github_runner.aws_cloudwatch_log_group.github_task_runner.name,
"awslogs-region" : var.aws_region,
"awslogs-stream-prefix" : split("/", data.terraform_remote_state.base_framework.outputs.github_runner.aws_cloudwatch_log_group.github_task_runner.name)[1]
}
}
}
])
}
42 changes: 42 additions & 0 deletions test/terraform_modules/fargate-task/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}

backend s3 {
bucket = "nr-coreint-terraform-tfstates"
dynamodb_table = "nr-coreint-terraform-locking"
key = "integrations/oracledb/fargate-task.tfstate"
region = "us-east-1"
profile = "base-framework"
}
}

# ########################################### #
# AWS #
# ########################################### #
provider aws {
region = var.aws_region
profile = var.aws_profile

default_tags {
tags = {
"owning_team" = "COREINT"
"purpose" = "development-integration-environments"
"integration" = "nri-oracledb"
}
}
}

# Variables so we can change them using Environment variables.
variable aws_region {
type = string
default = "us-east-1"
}
variable aws_profile {
type = string
default = "coreint"
}
11 changes: 11 additions & 0 deletions test/terraform_modules/fargate-task/remote-backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data terraform_remote_state base_framework {
backend = "s3"

config = {
bucket = "nr-coreint-terraform-tfstates"
dynamodb_table = "nr-coreint-terraform-locking"
key = "base-framework/global-state-store.tfstate"
region = "us-east-1"
profile = "base-framework"
}
}
Loading

0 comments on commit 03530ad

Please sign in to comment.