Skip to content

Commit 950ed3e

Browse files
Add launch-ec2-runner-with-fallback action
This action is used to launch an EC2 instance (either as a spot instance or a dedicated instance) in a desired availability zone. If no availability, then backup availability zones will be tried until one is successful. Signed-off-by: Courtney Pacheco <[email protected]>
1 parent 68bc43a commit 950ed3e

File tree

13 files changed

+1541
-1
lines changed

13 files changed

+1541
-1
lines changed

.github/workflows/test.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# yamllint disable rule:line-length
3+
4+
name: Test
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- "main"
11+
- "release-**"
12+
paths:
13+
- '**.py'
14+
- 'requirements**.txt'
15+
- 'tox.ini'
16+
- 'actions/**.sh'
17+
- '.github/workflows/test.yml' # This workflow
18+
pull_request:
19+
branches:
20+
- "main"
21+
- "release-**"
22+
paths:
23+
- '**.py'
24+
- 'requirements**.txt'
25+
- 'tox.ini'
26+
- 'actions/**.sh'
27+
- '.github/workflows/test.yml' # This workflow
28+
29+
env:
30+
LC_ALL: en_US.UTF-8
31+
32+
defaults:
33+
run:
34+
shell: bash
35+
36+
permissions:
37+
contents: read
38+
39+
jobs:
40+
test-workflow-ready:
41+
permissions:
42+
checks: read
43+
uses: ./.github/workflows/status-checks.yml
44+
with:
45+
# The unit and functional tests will not start until the following job IDs have succeeded
46+
job_ids: >- # Space-separated job ids to wait on for status checks
47+
DCO
48+
shellcheck
49+
lint-workflow-complete
50+
51+
test:
52+
# Start name with 'test:' for test-workflow-complete job_ids
53+
name: "test: ${{ matrix.python }} on ${{ matrix.platform }}"
54+
needs: ["test-workflow-ready"]
55+
runs-on: "${{ matrix.platform }}"
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
python:
60+
- "3.10"
61+
- "3.11"
62+
platform:
63+
- "ubuntu-latest"
64+
include:
65+
- python: "3.11"
66+
platform: "macos-latest"
67+
steps:
68+
- name: "Harden Runner"
69+
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
70+
with:
71+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
72+
73+
- name: Checkout
74+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
75+
with:
76+
# https://github.com/actions/checkout/issues/249
77+
fetch-depth: 0
78+
79+
# Always apt-get update before installing any extra packages
80+
# https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/customizing-github-hosted-runners#installing-software-on-ubuntu-runners
81+
- name: Update apt index
82+
if: startsWith(matrix.platform, 'ubuntu')
83+
run: |
84+
sudo apt-get update
85+
86+
- name: Install tools on MacOS
87+
if: startsWith(matrix.platform, 'macos')
88+
run: |
89+
brew install expect coreutils bash skopeo
90+
91+
- name: Setup Python ${{ matrix.python }}
92+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
93+
with:
94+
python-version: ${{ matrix.python }}
95+
## TODO: Uncomment once this change merges into `main`. We can't use caching until it's merged.
96+
# cache: pip
97+
# cache-dependency-path: |
98+
# **/requirements*.txt
99+
100+
- name: Install dependencies
101+
run: |
102+
python -m pip install --upgrade pip
103+
python -m pip install tox tox-gh>=1.2
104+
105+
- name: Run Bash "unit" tests with tox on MacOS
106+
if: startsWith(matrix.platform, 'macos')
107+
run: |
108+
tox -e launch-ec2-runner-with-fallback
109+
110+
# Default shell on Ubuntu is 'dash', so we need to override the default shell
111+
- name: Run Bash "unit" tests with tox on Linux
112+
if: startsWith(matrix.platform, 'ubuntu')
113+
run: |
114+
# Forcefully overwrite the symlink from `/bin/sh -> /bin/dash` to: `/bin/sh -> /bin/bash`.
115+
sudo ln -sf /bin/bash /bin/sh
116+
tox -e launch-ec2-runner-with-fallback
117+
shell: bash
118+
119+
test-workflow-complete:
120+
permissions:
121+
checks: read
122+
uses: ./.github/workflows/status-checks.yml
123+
with:
124+
job_ids: >- # Space-separated job ids to wait on for status checks
125+
test-workflow-ready
126+
test:

.yamllint.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ rules:
88
line-length:
99
max: 120
1010
allow-non-breakable-words: true
11-
allow-non-breakable-inline-mappings: false
11+
allow-non-breakable-inline-mappings: false
12+
ignore:
13+
# REASON: This file needs lines that are longer than 120 in order to load variables to the env
14+
- /actions/launch-ec2-runner-with-fallback/action.yml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Below is a list of the in-house GitHub actions stored in this repository:
1616
| Name | Description | Example Use Cases |
1717
| --- | --- | --- |
1818
| [free-disk-space](./actions/free-disk-space/free-disk-space.md) | Used to reclaim disk space on either a GitHub or EC2 runner. | <ul><li>If a CI job tends to fail due to "insufficient disk space"</li><li>If you want to reduce cloud costs by reclaiming disk space instead of increasing your writeable cloud storage to compensate for a bloated EC2 image</li></ul> |
19+
| [launch-ec2-runner-with-fallback](./actions/launch-ec2-runner-with-fallback/launch-ec2-runner-with-fallback.md) | Used launch an EC2 instance in AWS, either as a spot instance or a dedicated instance. If your preferred availability zone lacks availability for your instance type, "backup" availability zones will be tried. | <ul><li>Insufficient capacity in AWS (i.e., AWS lacks availablility for your desired EC2 instance type in your preferred availability zone)</li><li>Cost savings (i.e., You want to try launching your EC2 runner as a spot instance first)</li></ul> |
1920

2021
## How to Use One or More In-House GitHub Actions
2122

actions/free-disk-space/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
13
name: 'Free Disk Space'
24
description: 'Frees disk space on the runner'
5+
author: 'InstructLab'
36
runs:
47
using: "composite"
58
steps:

0 commit comments

Comments
 (0)