Skip to content

Github actions #16

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
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
18 changes: 18 additions & 0 deletions .github/actions/setup-terraform/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Setup Terraform"
description: "Sets up Terraform and initializes the configuration"
runs:
using: "composite"
steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.3
terraform_wrapper: false

- name: Configure provider
run: cp .github/provider.tf .
shell: bash

- name: Terraform init
run: terraform init
shell: bash
8 changes: 8 additions & 0 deletions .github/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
backend "azurerm" {
resource_group_name = "azure-blob"
storage_account_name = "azureblobrubygemdev"
container_name = "terraform"
key = "terraform.tfstate"
}
}
27 changes: 0 additions & 27 deletions .github/workflows/main.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/teardown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Teardown

on:
schedule:
- cron: "0 4 * * *"
workflow_dispatch:

permissions:
id-token: write
contents: read
env:
ARM_SKIP_PROVIDER_REGISTRATION: true
ARM_USE_OIDC: true
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}

jobs:
teardown-infrastructure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-terraform
- name: Terraform apply
run: terraform apply -auto-approve

clean_storage_containers:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Tests
env:
AZURE_ACCOUNT_NAME: ${{secrets.AZURE_ACCOUNT_NAME}}
AZURE_ACCESS_KEY: ${{secrets.AZURE_ACCESS_KEY}}
AZURE_PRIVATE_CONTAINER: ${{secrets.AZURE_PRIVATE_CONTAINER}}
AZURE_PUBLIC_CONTAINER: ${{secrets.AZURE_PUBLIC_CONTAINER}}
AZURE_PRINCIPAL_ID: ${{secrets.AZURE_PRINCIPAL_ID}}
run: bundle exec rake flush_test_container
104 changes: 104 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Run tests

on:
pull_request:
push:

permissions:
id-token: write
contents: read
env:
ARM_SKIP_PROVIDER_REGISTRATION: true
ARM_USE_OIDC: true
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}

jobs:
deploy-infrastructure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-terraform
- name: Terraform apply
run: terraform apply -auto-approve -var "create_vm=true" -var "create_app_service=true" -var "ssh_key=${{ secrets.SSH_PUBLIC_KEY }}"

app_service_test:
needs: deploy-infrastructure
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install -y libvips sshuttle
- name: Checkout
uses: actions/checkout@v4
- uses: ./.github/actions/setup-terraform
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Tests
env:
AZURE_ACCOUNT_NAME: ${{secrets.AZURE_ACCOUNT_NAME}}
AZURE_ACCESS_KEY: ${{secrets.AZURE_ACCESS_KEY}}
AZURE_PRIVATE_CONTAINER: ${{secrets.AZURE_PRIVATE_CONTAINER}}
AZURE_PUBLIC_CONTAINER: ${{secrets.AZURE_PUBLIC_CONTAINER}}
AZURE_PRINCIPAL_ID: ${{secrets.AZURE_PRINCIPAL_ID}}
run: bundle exec rake test_app_service

azurevm_test:
needs: deploy-infrastructure
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install -y libvips sshuttle
- name: SSH key
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p /home/runner/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > /home/runner/.ssh/id_rsa
chmod 600 /home/runner/.ssh/id_rsa
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/id_rsa
- name: Checkout
uses: actions/checkout@v4
- uses: ./.github/actions/setup-terraform
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Tests
env:
AZURE_ACCOUNT_NAME: ${{secrets.AZURE_ACCOUNT_NAME}}
AZURE_ACCESS_KEY: ${{secrets.AZURE_ACCESS_KEY}}
AZURE_PRIVATE_CONTAINER: ${{secrets.AZURE_PRIVATE_CONTAINER}}
AZURE_PUBLIC_CONTAINER: ${{secrets.AZURE_PUBLIC_CONTAINER}}
AZURE_PRINCIPAL_ID: ${{secrets.AZURE_PRINCIPAL_ID}}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: bundle exec rake test_azure_vm

test:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install -y libvips
- name: Checkout
uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Tests
env:
AZURE_ACCOUNT_NAME: ${{secrets.AZURE_ACCOUNT_NAME}}
AZURE_ACCESS_KEY: ${{secrets.AZURE_ACCESS_KEY}}
AZURE_PRIVATE_CONTAINER: ${{secrets.AZURE_PRIVATE_CONTAINER}}
AZURE_PUBLIC_CONTAINER: ${{secrets.AZURE_PUBLIC_CONTAINER}}
AZURE_PRINCIPAL_ID: ${{secrets.AZURE_PRINCIPAL_ID}}
run: bundle exec rake test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ terraform.tfstate
terraform.tfstate.backup
.terraform.tfstate.lock.info
*.tfvars
provider.tf

__azurite_db*
__blobstorage__/
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.6
3 changes: 3 additions & 0 deletions bin/proxy-vps
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec sshuttle -e "ssh -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" -r "$(terraform output --raw vm_username)@$(terraform output --raw vm_ip)" 0/0
5 changes: 5 additions & 0 deletions bin/start-app-service-ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

resource_group=$(terraform output --raw "resource_group")
app_name=$(terraform output --raw "app_service_app_name")
exec az webapp create-remote-connection --resource-group $resource_group --name $app_name
10 changes: 0 additions & 10 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,4 @@
scripts.generate-env-file.exec = ''
terraform output -raw devenv_local_nix > devenv.local.nix
'';

scripts.proxy-vps.exec = ''
exec sshuttle -e "ssh -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" -r "$(terraform output --raw vm_username)@$(terraform output --raw vm_ip)" 0/0
'';

scripts.start-app-service-ssh.exec = ''
resource_group=$(terraform output --raw "resource_group")
app_name=$(terraform output --raw "app_service_app_name")
exec az webapp create-remote-connection --resource-group $resource_group --name $app_name
'';
}
8 changes: 4 additions & 4 deletions test/support/app_service_vpn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppServiceVpn

attr_reader :header, :endpoint

def initialize(verbose: false)
def initialize(verbose: true)
@verbose = verbose
establish_vpn_connection
end
Expand All @@ -25,7 +25,7 @@ def establish_vpn_connection

puts "Establishing VPN connection..."

tunnel_stdin, tunnel_stdout, @tunnel_wait_thread = Open3.popen2e([ "sshuttle", "-e", "ssh -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null", "-r", "#{username}:#{password}@#{HOST}:#{port}", "0/0" ].shelljoin)
tunnel_stdin, tunnel_stdout, @tunnel_wait_thread = Open3.popen2e([ "sshuttle", "-e", "ssh -o PubkeyAuthentication=no -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null", "-r", "#{username}:#{password}@#{HOST}:#{port}", "0/0" ].shelljoin)

connection_successful = false
tunnel_stdout.each do |line|
Expand All @@ -42,7 +42,7 @@ def establish_vpn_connection

def establish_app_service_tunnel
puts "Establishing tunnel connection to app service..."
connection_stdin, connection_stdout, @connection_wait_thread = Open3.popen2e("start-app-service-ssh")
connection_stdin, connection_stdout, @connection_wait_thread = Open3.popen2e("bin/start-app-service-ssh")

port = nil
username = nil
Expand Down Expand Up @@ -74,7 +74,7 @@ def extract_msi_info
puts "Extracting MSI endpoint info..."
endpoint = nil
header = nil
Net::SSH.start(HOST, username, password:, port:) do |ssh|
Net::SSH.start(HOST, username, password:, port:, encryption: 'aes256-ctr', hmac: 'hmac-sha1-96', auth_methods: ['password']) do |ssh|
endpoint = ssh.exec! [ "bash", "-l", "-c", %(printf "%s" "$IDENTITY_ENDPOINT") ].shelljoin
header = ssh.exec! [ "bash", "-l", "-c", %(printf "%s" "$IDENTITY_HEADER") ].shelljoin
end
Expand Down
3 changes: 2 additions & 1 deletion test/support/azure_vm_vpn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
class AzureVmVpn
def initialize(verbose: false)
@verbose = verbose
stdin, stdout, @wait_thread = Open3.popen2e("proxy-vps")
stdin, stdout, @wait_thread = Open3.popen2e("bin/proxy-vps")
stdout.each do |line|
puts line if @verbose
break if line.include?("Connected to server")
end
end
Expand Down
Loading