Skip to content

Commit

Permalink
Merge pull request #2 from unity-sds/ucs-template
Browse files Browse the repository at this point in the history
Ucs template
  • Loading branch information
jonathansmolenski authored Apr 19, 2022
2 parents 82aa547 + 449b4c7 commit 023d41f
Show file tree
Hide file tree
Showing 23 changed files with 709 additions and 100 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ ucs-template ]
pull_request:
branches: [ ucs-template ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
branches: [ ucs-template ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

# Runs a set of commands using the runners shell
- name: Run integrated tests
run: |
echo Add other actions to build,
echo test, and deploy your project.
cd build
cd tests
sh run.sh
cat report.xml
17 changes: 15 additions & 2 deletions .github/workflows/deploy_eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,42 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Setup EKS via Terraform
# Set up current working directory with the repo contents
- uses: actions/checkout@v2

# Determine contents of working directory
- name: Display contents of working directory
run: ls -al


# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
# terraform_version: 0.13.0
cli_config_credentials_token: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}


## Check Terraform formatting
- name: Terraform Format
working-directory: ./terraform-unity
id: fmt
run: terraform fmt -check

## Init terraform
- name: Terraform Init
working-directory: ./terraform-unity
id: init
run: terraform init

## Validate Terraform
- name: Terraform Validate
working-directory: ./terraform-unity
id: validate
run: terraform validate -no-color

## Plan Terraform
- name: Terraform Plan
working-directory: ./terraform-unity
id: plan
run: terraform plan -no-color
continue-on-error: true
Expand All @@ -57,5 +69,6 @@ jobs:
run: exit 1

- name: Terraform Apply
working-directory: ./terraform-unity
# if: github.ref == 'refs/heads/smolenski_tf_test' && github.event_name == 'push'
run: terraform apply -auto-approve
148 changes: 132 additions & 16 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,36 @@ name: CI Deployment
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ ucs-template ]
pull_request:
branches: [ ucs-template ]
# push:
# branches: [ ucs-template ]
# pull_request:
# branches: [ ucs-template ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
branches: [ ucs-template ]
inputs:
sourceRepository:
description: 'Repository Source'
required: true
type: choice
default: 'unity-sds/unity-cs-sps-demo'
options:
- unity-sds/unity-cs-sps-demo
sourceBranch:
description: 'Repository Branch'
required: true
type: choice
default: 'smolenski_tf_test_mcp'
options:
- smolenski_tf_test_mcp
- smolenski_tf_test_jpl_aws


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# This workflow contains a single job called "deployment"
deployment:
# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand All @@ -28,15 +45,114 @@ jobs:

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
run: ls -al

# Checks-out the repo to deploy
# While cloning the repository:
# - it clones the repo into the given `path`
# - it checks out the branch defined at `ref`
- name: Clone the service repository for deployment
uses: actions/checkout@v2
with:
repository: ${{ github.event.inputs.sourceRepository }}
path: resources/deployable
ref: ${{ github.event.inputs.sourceBranch }}

# Runs a single command using the runners shell
- name: Run a one-line script
run: ls -al resources/deployable

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
# terraform_version: 0.13.0
cli_config_credentials_token: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}


## Verify that the Terraform directory exists in the remote repo
- name: Check for Terraform Directory
id: terraform_directory
uses: andstor/file-existence-action@v1
with:
files: "./resources/deployable/terraform-unity"
- name: Terraform Directory Exists
if: steps.terraform_directory.outputs.files_exists != 'true'
run: exit 1

## Check Terraform formatting
- name: Terraform Format
working-directory: ./resources/deployable/terraform-unity
id: fmt
run: terraform fmt -check

## Init terraform
- name: Terraform Init
working-directory: ./resources/deployable/terraform-unity
id: init
run: terraform init

## Validate Terraform
- name: Terraform Validate
working-directory: ./resources/deployable/terraform-unity
id: validate
run: terraform validate -no-color

## Plan Terraform
- name: Terraform Plan
working-directory: ./resources/deployable/terraform-unity
id: plan
run: terraform plan -no-color
continue-on-error: true

## Fail the job if terraform plan doesn't succeed
- name: Terraform Plan Status
working-directory: ./resources/deployable/terraform-unity
if: steps.plan.outcome == 'failure'
run: exit 1

- name: Terraform Apply
working-directory: ./resources/deployable/terraform-unity
# if: github.ref == 'refs/heads/smolenski_tf_test' && github.event_name == 'push'
run: terraform apply -auto-approve


## Verify that the smoke test exists
- name: Check for Smoke Tests
id: smoke_test_file
uses: andstor/file-existence-action@v1
with:
files: "./resources/deployable/smoketest/smoketest.py"
- name: Smoke Test Exists
if: steps.smoke_test_file.outputs.files_exists != 'true'
run: exit 1


- name: Post-Deployment Smoke Test
uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: 'x64'
- run: |
cd ./resources/deployable/smoketest
pip install -r requirements.txt
python3 smoketest.py
# - name: Negative Smoke Test Check
# run: |
# cd ./resources/deployable/smoketest
# sh smokefail.sh



# Runs a set of commands using the runners shell
- name: Run integrated tests
run: |
echo Add other actions to build,
echo test, and deploy your project.
cd build
cd tests
sh run.sh
cat report.xml
# - name: Only run this if the test running script exists
# run: '(test -f build/tests/run.sh && sh build/tests/run.sh && cat build/tests/report.xml) || echo No test script, skipping step'

# Run terraform scripts
# - name: Run terraform scripts in a docker container
# run: docker run --rm --privileged aptman/qus -s -- -p

# - name: build
# uses: docker://hashicorp/terraform:latest
# with:
# args: make
20 changes: 18 additions & 2 deletions .github/workflows/teardown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
branches: [ ucs-template ]
inputs:
sourceRepository:
description: 'Repository Source'
required: true
type: choice
default: 'unity-sds/unity-cs-sps-demo'
options:
- unity-sds/unity-cs-sps-demo
sourceBranch:
description: 'Repository Branch'
required: true
type: choice
default: 'smolenski_tf_test_mcp'
options:
- smolenski_tf_test_mcp
- smolenski_tf_test_jpl_aws

# These steps will tear down a unity project using the provided terraform scripts
jobs:
Expand All @@ -25,9 +41,9 @@ jobs:
- name: Clone the service repository for deployment
uses: actions/checkout@v2
with:
repository: unity-sds/unity-cs-sps-demo
repository: ${{ github.event.inputs.sourceRepository }}
path: resources/deployable
ref: smolenski_tf_test
ref: ${{ github.event.inputs.sourceBranch }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
Expand Down
Loading

0 comments on commit 023d41f

Please sign in to comment.