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

Add Release Workflow #14

Merged
merged 22 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1ce6208
terrabuttler: Add __init__.py
MiguelNdeCarvalho May 9, 2022
134e093
terrabutler: Fix typo on name
MiguelNdeCarvalho May 10, 2022
fb453bf
terrabutler: More fixes on the typo
MiguelNdeCarvalho May 10, 2022
8072208
Merge branch 'master' into changes-to-global-script
MiguelNdeCarvalho May 10, 2022
9158bfb
.github: workflows: test.yml: Use master as branch
MiguelNdeCarvalho May 10, 2022
58b3090
.vscode: settings.json: Use flake8 to lint locally
MiguelNdeCarvalho May 10, 2022
5e2c634
terrabutler: Move main to module folder and change name
MiguelNdeCarvalho May 10, 2022
3dec994
terrabutler: click.py: Use main instead of main_cli
MiguelNdeCarvalho May 10, 2022
30370bb
terrabutler: click.py: Fix misisng typos
MiguelNdeCarvalho May 10, 2022
df00683
terrabutler: Add __main__.py
MiguelNdeCarvalho May 10, 2022
7fc308e
Add LICENCE
MiguelNdeCarvalho May 10, 2022
c8c0a80
Add setup.py
MiguelNdeCarvalho May 10, 2022
e8ca418
setup.py: Fix README extension
MiguelNdeCarvalho May 10, 2022
8fb343a
setup.py: Add find_version function
MiguelNdeCarvalho May 10, 2022
426ab59
Add run.py
MiguelNdeCarvalho May 10, 2022
3f62f26
terrabutler: __init__.py: Add name
MiguelNdeCarvalho May 10, 2022
c1525ef
terrabutler: click.py: Enable versioning via click
MiguelNdeCarvalho May 10, 2022
e61ef7f
terrabutler: click.py: Fix typo
MiguelNdeCarvalho May 10, 2022
c696386
terrabutler: __init__.py: Set version to 1.0.0-beta
MiguelNdeCarvalho May 10, 2022
1cfba22
.gitignore: Remove .spec from it
MiguelNdeCarvalho May 10, 2022
c07892d
.github: workflows: Add release.yml
MiguelNdeCarvalho May 10, 2022
b7ef3ba
terrabutler: Add terrabutler.spec
MiguelNdeCarvalho May 10, 2022
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
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release Terrabutler

on:
push:
tags:
- '*'

jobs:
release-terrabutler:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get Current Tag
uses: WyriHaximus/github-action-get-previous-tag@master
id: tag
- name: Build Python Module
uses: JackMcKew/pyinstaller-action-linux@main
with:
path: terrabutler
spec: terrabutler
- name: Copy needed files to build directory
run: |
cp README.md src/dist/linux
- name: Create archive of build (.tar.gz)
uses: sibiraj-s/action-archiver@v1
with:
working-directory: './'
path: 'src/dist/linux/**'
format: tar
gzip: true
output: terrabutler-${{ RUNNER_OS }}-${{ RUNNER_ARCH }}-${{ steps.tag.outputs.tag }}.tar.gz
- name: Add artifact to Release
uses: softprops/action-gh-release@v1
with:
files: terrabutler-${{ RUNNER_OS }}-${{ RUNNER_ARCH }}-${{ steps.tag.outputs.tag }}.tar.gz
- name: Upload artifact to S3 bucket
uses: zdurham/s3-upload-github-action@master
with:
args: --acl public-read
env:
FILE: ./terrabutler-${{ RUNNER_OS }}-${{ RUNNER_ARCH }}-${{ steps.tag.outputs.tag }}.tar.gz
AWS_REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
S3_KEY: ${{ secrets.AWS_S3_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test Code
on:
pull_request:
branches:
- main
- master

jobs:
lint-python:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}
674 changes: 674 additions & 0 deletions LICENCE

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
from terrabutler.click import main

if __name__ == "__main__":
sys.exit(main())
67 changes: 67 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
import re
from setuptools import setup


def find_version(path):
version_file = read(path)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")


# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


setup(
name="terrabutler",
version=find_version("terrabutler/__init__.py"),
author="AnguloSólido",
description=("A tool to manage Terraform projects easier."),
long_description=read("README.md"),
license="GPL-3.0",
keywords="terraform manager",
url="https://github.com/angulo-solido/terrabutler",
scripts=["bin/terrabutler"],
packages=["terrabutler"],
install_requires=[
"boto3>=1.20.0",
"botocore>=1.20.0",
"click>=8.0.0",
"jmespath>=0.10.0",
"mccabe>=0.6.0",
"pycodestyle>=2.8.0",
"pyflakes>=2.4.0",
"python-dateutil>=2.8.0",
"s3transfer>=0.5.0",
"six>=1.16.0",
"urllib3>=1.26.0"
],
python_requires=">= 3.6",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Utilities"
],
project_urls={
"Source": "https://github.com/angulo-solido/terrabutler",
"Changelog": "https://github.com/angulo-solido/terrabutler/releases",
},
)
2 changes: 2 additions & 0 deletions terrabutler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__name__ = "terrabutler"
__version__ = '1.0.0-beta'
5 changes: 5 additions & 0 deletions terrabutler/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
from terrabutler.click import main

if __name__ == "__main__":
sys.exit(main())
28 changes: 15 additions & 13 deletions main.py → terrabutler/click.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
#!/usr/bin/env python3

"""
Pyhton wrapper used to manage environments and terraform commands
Python wrapper used to manage environments and terraform commands
"""

import click
from colorama import Fore
from os import path
from terrabuttler.env import (
from terrabutler.__init__ import (
__name__,
__version__
)
from terrabutler.env import (
create_env,
delete_env,
get_current_env,
set_current_env,
get_available_envs
)
from terrabuttler.tf import (
from terrabutler.tf import (
terraform_args_print,
terraform_command_runner
)
from terrabuttler.settings import (
from terrabutler.settings import (
check_settings,
get_settings,
validate_settings
)
from terrabuttler.inception import (
from terrabutler.inception import (
inception_init,
inception_init_needed
)


@click.group(context_settings=dict(help_option_names=['-h', '-help',
'--help']))
def main_cli():
@click.version_option(version=__version__, prog_name=__name__.capitalize(),
message='%(prog)s v%(version)s')
def main():
check_settings()
validate_settings()


@main_cli.group(name="env", help="Manage environments")
@main.group(name="env", help="Manage environments")
def env_cli():
inception_init_needed()


@main_cli.command(name="init", help="Initialize the manager")
@main.command(name="init", help="Initialize the manager")
def init_cli():
inception_init()


@main_cli.group(name="tf", help="Manage terraform commands")
@main.group(name="tf", help="Manage terraform commands")
@click.pass_context
@click.option('-site', metavar='SITE', required=True, help="Site where to run"
"terraform.")
Expand Down Expand Up @@ -577,7 +583,3 @@ def tf_version_cli(ctx, json):
args.append("-json")

terraform_command_runner("version", args, "", ctx.obj['SITE'])


if __name__ == '__main__':
main_cli()
12 changes: 6 additions & 6 deletions terrabuttler/env.py → terrabutler/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from terrabuttler.settings import get_settings
from terrabuttler.tf import terraform_init_all_sites
from terrabutler.settings import get_settings
from terrabutler.tf import terraform_init_all_sites
from click import confirm
from colorama import Fore
import boto3
Expand All @@ -16,9 +16,9 @@


def create_env(env, confirmation, temporary, apply, s3):
from terrabuttler.settings import write_settings
from terrabuttler.tf import terraform_apply_all_sites
from terrabuttler.variables import generate_var_files
from terrabutler.settings import write_settings
from terrabutler.tf import terraform_apply_all_sites
from terrabutler.variables import generate_var_files
available_envs = get_available_envs(s3)

if env in available_envs:
Expand Down Expand Up @@ -52,7 +52,7 @@ def create_env(env, confirmation, temporary, apply, s3):


def delete_env(env, confirmation, destroy, s3):
from terrabuttler.tf import terraform_destroy_all_sites
from terrabutler.tf import terraform_destroy_all_sites
available_envs = get_available_envs(s3)
current_env = get_current_env()
org = get_settings()["general"]["organization"]
Expand Down
4 changes: 2 additions & 2 deletions terrabuttler/inception.py → terrabutler/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def inception_init_needed():


def inception_init():
from terrabuttler.env import reload_direnv
from terrabuttler.settings import get_settings
from terrabutler.env import reload_direnv
from terrabutler.settings import get_settings
site_dir = path.realpath(get_settings()["locations"]["inception_dir"])
backend_dir = path.realpath(get_settings()["locations"]["backend_dir"])

Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions terrabutler/terrabutler.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['__main__.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='terrabutler',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='terrabutler',
)
6 changes: 3 additions & 3 deletions terrabuttler/tf.py → terrabutler/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import signal
import subprocess
from colorama import Fore
from terrabuttler.settings import get_settings
from terrabutler.settings import get_settings

# Values from Config
backend_dir = os.path.realpath(get_settings()["locations"]["backend_dir"])
Expand Down Expand Up @@ -45,7 +45,7 @@ def terraform_args_builder(needed_args, site, backend_dir, var_dir):
"""
Create array of needed arguments for backend or var files
"""
from terrabuttler.env import get_current_env
from terrabutler.env import get_current_env
env = get_current_env()

if needed_args == "backend":
Expand Down Expand Up @@ -83,7 +83,7 @@ def terraform_command_runner(command, args, needed_args, site):
"""
Run tfenv and run the terraform command
"""
from terrabuttler.env import get_current_env
from terrabutler.env import get_current_env
site_dir = os.path.realpath(f"site_{site}")
env = get_current_env()

Expand Down
2 changes: 1 addition & 1 deletion terrabuttler/variables.py → terrabutler/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ascii_letters,
digits
)
from terrabuttler.settings import get_settings
from terrabutler.settings import get_settings


REGION = get_settings()["environments"]["default"]["region"]
Expand Down