Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Terraform refactor / Go buildpack deploy #75

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
51eb447
Terraform updates for CGov
jadudm Jan 4, 2025
3e4783a
Continued refactoring/restructuring
jadudm Jan 4, 2025
b72a8d4
Continued refactoring
jadudm Jan 4, 2025
2ac4ecf
Adding in all the services
jadudm Jan 5, 2025
0d80973
Deploys infra, not apps
jadudm Jan 5, 2025
db2fcd7
Adding a demo workflow
jadudm Jan 5, 2025
6471f5c
Trying a workflow dispatch.
jadudm Jan 5, 2025
f443a24
A test deploy script
jadudm Jan 5, 2025
ae71729
Will this work?
jadudm Jan 5, 2025
e030c7e
Dispatch only?
jadudm Jan 5, 2025
31c7fca
Push might be needed?
jadudm Jan 5, 2025
6ef5a50
Forgot permissions
jadudm Jan 5, 2025
cd39054
Root is needed in the runner
jadudm Jan 5, 2025
faffed1
Do more work in the workflow
jadudm Jan 5, 2025
cd2d03c
Iterating GH Action
jadudm Jan 5, 2025
d817626
Iterating GH Action
jadudm Jan 5, 2025
2d8e780
Iterating GH Action
jadudm Jan 5, 2025
4b372c4
Iterating GH Action Sun Jan 5 11:29:05 AM EST 2025
jadudm Jan 5, 2025
76c4057
Iterating GH Action Sun Jan 5 11:33:31 AM EST 2025
jadudm Jan 5, 2025
e810c0d
Iterating GH Action Sun Jan 5 11:34:39 AM EST 2025
jadudm Jan 5, 2025
c1e679e
Iterating GH Action Sun Jan 5 11:35:56 AM EST 2025
jadudm Jan 5, 2025
b2dd3de
Iterating GH Action Sun Jan 5 11:38:56 AM EST 2025
jadudm Jan 5, 2025
f22e2a7
Moving towards S3 backed deployment
jadudm Jan 5, 2025
f4983ea
Another approach...
jadudm Jan 5, 2025
d73e63f
Iterating GH Action Sun Jan 5 03:51:20 PM EST 2025
jadudm Jan 5, 2025
1b6f554
Iterating GH Action Sun Jan 5 09:00:11 PM EST 2025
jadudm Jan 6, 2025
84ca964
Iterating GH Action Sun Jan 5 09:04:27 PM EST 2025
jadudm Jan 6, 2025
4cdec88
Iterating GH Action Sun Jan 5 09:07:12 PM EST 2025
jadudm Jan 6, 2025
39e6172
Iterating GH Action Sun Jan 5 09:12:47 PM EST 2025
jadudm Jan 6, 2025
8a8ddfa
Iterating GH Action Sun Jan 5 09:20:42 PM EST 2025
jadudm Jan 6, 2025
2619bf1
Iterating GH Action Sun Jan 5 09:23:45 PM EST 2025
jadudm Jan 6, 2025
27241ef
Iterating GH Action Sun Jan 5 09:25:40 PM EST 2025
jadudm Jan 6, 2025
a78aaa3
Iterating GH Action Sun Jan 5 09:27:19 PM EST 2025
jadudm Jan 6, 2025
c9e7c96
Iterating GH Action Sun Jan 5 09:32:24 PM EST 2025
jadudm Jan 6, 2025
e434613
Iterating GH Action Sun Jan 5 09:35:38 PM EST 2025
jadudm Jan 6, 2025
d77d25f
Iterating GH Action Sun Jan 5 09:37:34 PM EST 2025
jadudm Jan 6, 2025
660c6b7
Iterating GH Action Sun Jan 5 09:41:44 PM EST 2025
jadudm Jan 6, 2025
e958858
Iterating GH Action Mon Jan 6 08:45:53 AM EST 2025
jadudm Jan 6, 2025
64ebc53
Iterating GH Action Mon Jan 6 03:17:23 PM EST 2025
jadudm Jan 6, 2025
3a4ce4b
Iterating GH Action Mon Jan 6 03:21:36 PM EST 2025
jadudm Jan 6, 2025
551a3f4
Iterating GH Action Mon Jan 6 03:24:24 PM EST 2025
jadudm Jan 6, 2025
f13a88d
Iterating GH Action Mon Jan 6 03:25:20 PM EST 2025
jadudm Jan 6, 2025
688eac7
Iterating GH Action Mon Jan 6 03:27:47 PM EST 2025
jadudm Jan 6, 2025
68116aa
Iterating GH Action Mon Jan 6 03:28:33 PM EST 2025
jadudm Jan 6, 2025
0a79b92
Iterating GH Action Mon Jan 6 03:29:37 PM EST 2025
jadudm Jan 6, 2025
dc1ddbe
Interim, stashing
jadudm Jan 7, 2025
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
19 changes: 19 additions & 0 deletions .github/workflows/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on:
workflow_dispatch:
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
115 changes: 115 additions & 0 deletions .github/workflows/deploy-to-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#
# To manually trigger:
# gh workflow run --ref jadudm/tf-0103 --field environment=dev deploy-to-dev.yaml
#
name: Deploy to space
on:
# push:
# branches:
# - jadudm/tf-0103
workflow_dispatch:
inputs:
environment:
required: true
type: string
workflow_call:
inputs:
environment:
required: true
type: string

jobs:
deploy:
name: apply ( ${{ inputs.environment }} )
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
KEY: "terraform.tfstate.${{ inputs.environment }}"
TF_VAR_cf_user: ${{ secrets.CF_USERNAME }}
TF_VAR_cf_password: ${{ secrets.CF_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_CONFIG_FILE: "${GITHUB_WORKSPACE}/aws-config"
AWS_SHARED_CREDENTIALS_FILE: "${GITHUB_WORKSPACE}/aws-credentials"
steps:

# This leaves the repository checked out in ${GITHUB_WORKSPACE}.
# So, ${GITHUB_WORKSPACE}/terraform is where the TF lives.
- name: Checkout
uses: actions/checkout@v4

- name: what is there
run: |
ls -alh "${GITHUB_WORKSPACE}"
ls -alh "${GITHUB_WORKSPACE}/terraform"

- name: Install CloudFoundry CLI v8
run: |
curl -k -O -L https://github.com/cloudfoundry/cli/releases/download/v8.8.0/cf8-cli-installer_8.8.0_x86-64.deb
sudo apt-get install --assume-yes ./cf8-cli-installer_8.8.0_x86-64.deb

# This may want to become TF actions
- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.10.3"

# We use ${{ secret.X }} to reference secrets, and
# we use ${{ vars.X }} to access environment variables
- name: Authenticate against Cloud.gov
run: |
cf api api.fr.cloud.gov
cf auth ${{ secrets.CF_USERNAME }} ${{ secrets.CF_PASSWORD }}
cf target -o ${{ vars.CF_ORG }} -s ${{ vars.CF_SPACE }}

# https://stackoverflow.com/questions/14268097/do-i-need-cat-to-write-a-heredoc-to-a-file
# https://stackoverflow.com/questions/63048738/how-to-declare-variables-for-s3-backend-in-terraform
- name: Setup TF creds for state bucket
run: |
tee "${GITHUB_WORKSPACE}/terraform/${{ inputs.environment }}/backend_${{ inputs.environment }}.config" <<EOF
bucket="${{ secrets.TF_VAR_BUCKET_NAME }}"
region="${{ secrets.TF_VAR_AWS_DEFAULT_REGION}}"
access_key="${{ secrets.TF_VAR_AWS_ACCESS_KEY_ID }}"
secret_key="${{ secrets.TF_VAR_SECRET_ACCESS_KEY }}"
endpoints={ s3 = "https://s3-${{ secrets.TF_VAR_AWS_DEFAULT_REGION }}.amazonaws.com/" }
EOF

- name: Setup TF vars for execution
run: |
tee "${GITHUB_WORKSPACE}/terraform/${{ inputs.environment }}/terraform.tfvars" <<EOF
cf_username = "${{ secrets.CF_USERNAME }}"
cf_password = "${{ secrets.CF_PASSWORD }}"
api_key = "FIXME"
cf_space_guid = "${{ secrets.CF_SPACE_GUID }}"
cf_org_guid = "${{ secrets.CF_ORG_GUID }}"
EOF

# - name: Setup AWS
# run: |
# tee "${GITHUB_WORKSPACE}/aws-credentials" <<EOF
# [default]
# aws_access_key_id="${{ secrets.TF_VAR_AWS_ACCESS_KEY_ID }}"
# aws_secret_access_key="${{ secrets.TF_VAR_SECRET_ACCESS_KEY }}"
# EOF
# chmod 600 "${GITHUB_WORKSPACE}/aws-credentials"
# tee "${GITHUB_WORKSPACE}/aws-config" <<EOF
# [default]
# region="${{ secrets.TF_VAR_AWS_DEFAULT_REGION }}"
# EOF

- name: TF init
run: |
pushd ${GITHUB_WORKSPACE}/terraform/${{ inputs.environment }}
terraform init -backend-config="./backend_${{ inputs.environment }}.config" || echo "Failed" && exit
popd

- name: TF plan
uses: dflook/terraform-plan@v1
with:
path: "${GITHUB_WORKSPACE}/terraform/${{ inputs.environment }}/main.tf"
backend_config_file: "${GITHUB_WORKSPACE}/terraform/${{ inputs.environment }}/backend_${{ inputs.environment}}.config"

# - name: TF apply
# run: |
# pushd ${GITHUB_WORKSPACE}/terraform/${{ inputs.environment }}
# make apply
# popd
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ build: clean config generate
# cd cmd/validate ; make build
echo "build walk"
cd cmd/walk ; make build
echo "copy assets"
cd assets ; rm -rf static/assets ; unzip -qq static.zip

.PHONY: up
up: build
Expand Down
7 changes: 0 additions & 7 deletions assets/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions assets/README.md

This file was deleted.

Binary file removed assets/static.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions config/services/admin.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ local credentials = [
local parameters = [
[
'debug_level',
{ cf: 'warn', container: 'debug', localhost: 'debug'},
{ cf: 'warn', container: 'debug', localhost: 'debug' },
],
] + B.parameters;

{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
6 changes: 4 additions & 2 deletions config/services/cf.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local A = import 'admin.libsonnet';
local E = import 'extract.libsonnet';
local EN = import 'entree.libsonnet';
local EX = import 'extract.libsonnet';
local F = import 'fetch.libsonnet';
local M = import 'migrate.libsonnet';
local P = import 'pack.libsonnet';
Expand All @@ -12,7 +13,8 @@ local W = import 'walk.libsonnet';
EIGHT_SERVICES: {
'user-provided': [
A.cf,
E.cf,
EN.cf,
EX.cf,
F.cf,
M.cf,
P.cf,
Expand Down
7 changes: 4 additions & 3 deletions config/services/entree.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ local credentials = [
local parameters = [
[
'workers',
{ cf: 10, container: 50, localhost: 10},
{ cf: 10, container: 50, localhost: 10 },
],
[
'debug_level',
{ cf: 'warn', container: 'info', localhost: 'debug'},
{ cf: 'warn', container: 'info', localhost: 'debug' },
],
] + B.parameters;

{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
3 changes: 2 additions & 1 deletion config/services/extract.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ local parameters = [
{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
3 changes: 2 additions & 1 deletion config/services/fetch.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ local parameters = [
{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
5 changes: 3 additions & 2 deletions config/services/migrate.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ local credentials = [];
local parameters = [
[
'debug_level',
{ cf: 'warn', container: 'debug', localhost: 'debug'},
{ cf: 'warn', container: 'debug', localhost: 'debug' },
],
] + B.parameters;

{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
3 changes: 2 additions & 1 deletion config/services/pack.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ local parameters = [
{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
3 changes: 2 additions & 1 deletion config/services/serve.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ local parameters = [
{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
3 changes: 2 additions & 1 deletion config/services/validate.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ local parameters = [
{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
3 changes: 2 additions & 1 deletion config/services/walk.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ local parameters = [
{
creds:: [[service] + x for x in credentials],
params:: [[service] + x for x in parameters],
cf: B.params('credentials', 'cf', service, self.creds) +
cf: { name: service } +
B.params('credentials', 'cf', service, self.creds) +
B.params('parameters', 'cf', service, self.params),
container: { name: service } +
B.params('credentials', 'container', service, self.creds) +
Expand Down
28 changes: 25 additions & 3 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Local .terraform directories
.terraform
**/.terraform
.terraform/*
**/.terraform/*

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

# Crash log files
crash.log
Expand All @@ -15,16 +20,22 @@ crash.*.log
# to change depending on the environment.
*.tfvars
*.tfvars.json
**/*.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
**/override.tf*
**/*_override.tf*


# Ignore transient lock info files created by terraform apply
.terraform.tfstate.lock.info
**/.terraform.tfstate.lock.info

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
Expand All @@ -35,10 +46,21 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
**/.terraformrc
**/terraform.rc

# Ignore the lock file; this is a demo, not about collab/CI/CD.
.terraform.lock.hcl
**/.terraform.lock.hcl

# developer files
dev/developers.tf
staging/developers.tf
production/developers.tf

zips/*
plans/*
app/*
zips
plans
app
**/zips
**/plans
**/app
Loading
Loading