Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainbourgeois committed May 2, 2023
1 parent 2dfd1a3 commit 0ceb2f1
Show file tree
Hide file tree
Showing 19 changed files with 2,391 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Description

Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change.

# Checklist:

- [ ] My code follows the [style guidelines](/CONTRIBUTING.md) of this project
- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that validate the behaviour of the software
- [ ] I validated that new and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
- [ ] I have bumped the version of the library
74 changes: 74 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '25 13 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
97 changes: 97 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:

jobs:
lint-report:
name: Lint report
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Install tox
run: pip install tox
- name: Run tests using tox
run: tox -e lint

static-analysis:
name: Static analysis
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Install tox
run: pip install tox
- name: Run tests using tox
run: tox -e static

unit-tests-with-coverage:
name: Unit tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Install tox
run: pip install tox
- name: Run tests using tox
run: tox -e unit

integration-test:
name: Integration tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup LXD
uses: canonical/setup-lxd@main
with:
channel: 5.12/stable
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
- name: Run integration tests
run: tox -e integration
- name: Archive Tested Charm
uses: actions/upload-artifact@v3
if: ${{ github.ref_name == 'main' }}
with:
name: tested-charm
path: .tox/**/httpreq-acme-operator_ubuntu-22.04-amd64.charm
retention-days: 5
- name: Archive charmcraft logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: charmcraft-logs
path: /home/runner/.local/state/charmcraft/log/*.log
- name: Archive juju crashdump
if: failure()
uses: actions/upload-artifact@v3
with:
name: juju-crashdump
path: juju-crashdump-*.tar.xz

publish-charm:
name: Publish Charm
needs: integration-test
runs-on: ubuntu-22.04
if: ${{ github.ref_name == 'main' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install charmcraft
run: sudo snap install charmcraft --classic
- name: Fetch Tested Charm
uses: actions/download-artifact@v3
with:
name: tested-charm
- name: Move charm in current directory
run: find ./ -name httpreq-acme-operator_ubuntu-22.04-amd64.charm -exec mv -t ./ {} \;
- name: Select Charmhub channel
uses: canonical/charming-actions/[email protected]
id: channel
- name: Upload charm to Charmhub
uses: canonical/charming-actions/[email protected]
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
channel: "${{ steps.channel.outputs.name }}"
43 changes: 43 additions & 0 deletions .github/workflows/promote.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Promote Charm

on:
workflow_dispatch:
inputs:
promotion:
type: choice
description: Channel to promote from
options:
- edge -> beta
- beta -> candidate
- candidate -> stable

jobs:
promote:
name: Promote Charm
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set target channel
env:
PROMOTE_FROM: ${{ github.event.inputs.promotion }}
run: |
if [ "${PROMOTE_FROM}" == "edge -> beta" ]; then
echo "promote-from=edge" >> ${GITHUB_ENV}
echo "promote-to=beta" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "beta -> candidate" ]; then
echo "promote-from=beta" >> ${GITHUB_ENV}
echo "promote-to=candidate" >> ${GITHUB_ENV}
elif [ "${PROMOTE_FROM}" == "candidate -> stable" ]; then
echo "promote-from=candidate" >> ${GITHUB_ENV}
echo "promote-to=stable" >> ${GITHUB_ENV}
fi
- name: Promote Charm
uses: canonical/charming-actions/[email protected]
with:
base-channel: 22.04
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
destination-channel: latest/${{ env.promote-to }}
origin-channel: latest/${{ env.promote-from }}
charmcraft-channel: latest/stable
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
venv/
build/
*.charm

.coverage
__pycache__/
*.py[cod]

.tox/

.idea/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Contributing

To make contributions to this charm, you'll need a working [development setup](https://juju.is/docs/sdk/dev-setup).

You can use the environments created by `tox` for development:

```shell
tox --notest -e unit
source .tox/unit/bin/activate
```

## Testing

This project uses `tox` for managing test environments. There are some pre-configured environments
that can be used for linting and formatting code when you're preparing contributions to the charm:

```shell
tox -e lint # code style
tox -e static # static analysis
tox -e unit # unit tests
tox -e integration # integration tests
tox # runs 'lint' and 'unit' environments
```


## Build
Building and publishing charms is done using charmcraft (official documentation
[here](https://juju.is/docs/sdk/publishing)). You can install charmcraft using `snap`:

```bash
sudo snap install charmcraft --channel=classic
```

Initialize LXD:

```bash
lxd init --auto
```

Go to the charm directory and run:

```bash
charmcraft pack
```
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# httpreq-acme-operator

## Description

Let's Encrypt certificates in the Juju ecosystem for answering the DNS-01
challenge through the HTTP Request plugin.

# Pre-requisites

This charm is a provider of the [`tls-certificates-interface`](https://github.com/canonical/tls-certificates-interface),
charms that require Let's Encrypt certificates need to implement the requirer side.

## Usage

Create a YAML configuration file with the following fields:

```yaml
httpreq-acme-operator:
email: <Account email address>
```

Deploy `httpreq-acme-operator`:

```bash
juju deploy httpreq-acme-operator --config <yaml config file>
```

Relate it to a `tls-certificates-requirer` charm:

```bash
juju relate httpreq-acme-operator:certificates <tls-certificates-requirer>
````

## Config

### Required configuration properties

- email: Let's Encrypt email address
### Optional configuration properties
- server: Let's Encrypt server to use (default: `https://acme-v02.api.letsencrypt.org/directory`)

## Relations

- `certificates`: `tls-certificates-interface` provider

## OCI Images

- [Lego Rock Image](https://github.com/canonical/lego-rock)
17 changes: 17 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type: "charm"
bases:
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"

parts:
charm:
build-packages:
- libffi-dev
- libssl-dev
- rustc
- cargo
- pkg-config
Loading

0 comments on commit 0ceb2f1

Please sign in to comment.