Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 4 additions & 12 deletions .github/workflows/publish-devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Publish devcontainer

on:
workflow_dispatch:
push:
branches:
- main

defaults:
run:
Expand All @@ -13,9 +10,6 @@ defaults:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- name: Checkout
Expand All @@ -35,19 +29,17 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v4

- name: Build, tag, and push image to GHCR [python ${{ matrix.python-version }}]
- name: Build, tag, and push image to GHCR
uses: docker/build-push-action@v7
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: |
GIT-SHA=${{ github.sha }}
PYTHON_VERSION=${{ matrix.python-version }}
PYTHON_VERSION=3.14
cache-from: type=gha,scope=compilerla
cache-to: type=gha,scope=compilerla,mode=max
context: .
file: .devcontainer/Dockerfile
file: appcontainer/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ matrix.python-version == '3.11' && format('ghcr.io/{0}:main', github.repository) || format('ghcr.io/{0}:main_{1}', github.repository, matrix.python-version) }}
${{ matrix.python-version == '3.11' && format('ghcr.io/{0}:{1}', github.repository, github.sha) || format('ghcr.io/{0}:{1}_{2}', github.repository, github.sha, matrix.python-version) }}
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# general things to ignore
build/
dist/
docs/_sources/
docs/.doctrees
.eggs/
*.egg-info/
*.egg
.env
*.py[cod]
__pycache__/
*.so
*~

# virtualenv
env*/
venv/
.venv*

# codecov / coverage
.coverage
cov_*
coverage.xml

# due to using tox and pytest
.tox
.cache
.pytest_cache/
.python-version
pip
.mypy_cache/

# misc
tmp.txt
.DS_Store
logs/
*.db
.pytype/
.idea/
90 changes: 59 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,78 @@
# template-devcontainer
# Slackronyms

A [template repository][template-repo] with a minimal [VS Code devcontainer][devcontainer] setup.
A Slack bot to help teams keep track of acronyms and other abbreviations.

Read the full documentation online: <https://compilerla.github.io/template-devcontainer>
## Setup

## Why?
### Create Your Slack App

Read more in our blog post: [How to support a platform-agnostic engineering team with VS Code Dev Containers](https://compiler.la/blog/2024/devcontainer-platform-agnostic-team).
1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose **From a manifest**.
1. Choose the workspace you want to install the application to.
1. Replace the contents of the JSON code block with the contents of [`manifest.json`](slackronyms/manifest.json).
1. Review the configuration and click **Create**.
1. Click **Install to Workspace** and **Allow** on the screen that follows. You'll then be redirected to the App Configuration dashboard.

## Features
### Environment Variables

- Base Docker image `python:3.11` includes support for common dev tooling like `git`, `curl`, `pip`, and `pre-commit`
- Includes VS Code extensions like [`GitLens`][gitlens] and [`Prettier`][prettier] and good default settings for the editor
- The [`pre-commit` configuration][pre-commit-config] includes a number of useful [`pre-commit-hooks`][pre-commit-hooks] and
Compiler's [`conventional-pre-commit`][conventional-pre-commit] hook
- A separate `docs` service builds documentation using [`mkdocs-material`][mkdocs-material]
Before you can run the app, you'll need to store some environment variables.

## Usage
1. Create a `.env` file from the sample at the root of the repo:

### Create a new repository
```sh
cp .env.sample .env
```

[Create a new repository from this template][generate].
1. Open your app's configuration page from [this list](https://api.slack.com/apps), click **OAuth & Permissions** in the left hand menu, then copy the Bot User OAuth Token. Paste it for `SLACK_BOT_TOKEN` in your `.env` file.
1. Click **Basic Information** from the left hand menu and follow the steps in the App-Level Tokens section to create an app-level token with the `connections:write` scope. Copy this token and paste it for `SLACK_APP_TOKEN` in your `.env` file.

### Run the devcontainer
### Developing in a VS Code dev container

With the `Remote - Containers` extension enabled, open the folder containing this repository inside VS Code.
We include a [Dev Container](https://code.visualstudio.com/docs/devcontainers/containers) configuration to help with local testing and development.

You should receive a prompt in the VS Code window; click `Reopen in Container` to run the development environment inside the devcontainer.
**The first time you run this project**, you'll have to manually build the app container in your terminal, because the dev container is built from the app container.

If you do not receive a prompt, or when you feel like starting from a fresh environment:
```sh
docker compose build app
```

1. `Ctrl/Cmd+Shift+P` to bring up the command palette in VS Code
1. Type `Remote-Containers` to filter the commands
1. Select `Rebuild and Reopen in Container` to completely rebuild the devcontainer
1. Select `Reopen in Container` to reopen the most recent devcontainer build
From there, connect to the dev container to begin working on the project:

1. Open the repository directory in VS Code
1. <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> to bring up the Command Palette
1. Start typing `devcontainers` to filter the command list
1. Select **Rebuild and Reopen in Container** to start from scratch
1. Select **Reopen in Container** to reopen the last dev container used

Once inside the dev container, you have to manually start the app by pressing <kbd>F5</kbd> (or switch the primary sidebar to Run and Debug and click the play button).

You should see output in a new terminal indicating that the app is now running, and you should now be able to invoke it in your Slack test workspace! Try the `/define` command to confirm.

After modifying app code, it will need to be restarted for the changes to take effect. Press <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>F5</kbd> to restart it (or click the refresh icon that appeared in the top menu bar).

The app can be stopped with <kbd>Shift</kbd>+<kbd>F5</kbd> (or the stop icon in the top menu bar).

To exit the dev container, use the **Reopen Folder Locally** command.

## Project Structure

This project was generated from Slack's [Bolt for Python template app](https://github.com/slack-samples/bolt-python-starter-template), which provided the basis for the code found in the `slackronyms` folder.

### `manifest.json`

`manifest.json` is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app.

### `app.py`

`app.py` is the entry point for the application, which gets run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests.

### `/listeners`

Every incoming request is routed to a "listener". Inside this directory, listeners are grouped based on the Slack Platform feature used, so `/listeners/shortcuts` handles incoming [Shortcuts](https://docs.slack.dev/interactivity/implementing-shortcuts/) requests, `/listeners/views` handles [View submissions](https://api.slack.com/reference/interaction-payloads/views#view_submission) and so on.

Slackronyms currently only implements a slash command listener for the `/define` command, which is found in [`/listeners/commands/define.py`](slackronyms/listeners/commands/define.py), but the other sample listeners are included in the codebase while we work out what other features we might want to leverage.

## License

[Apache 2.0](LICENSE)

[conventional-pre-commit]: https://github.com/compilerla/conventional-pre-commit
[devcontainer]: https://code.visualstudio.com/docs/remote/containers
[generate]: https://github.com/compilerla/template-devcontainer/generate
[gitlens]: https://gitlens.amod.io/
[mkdocs-material]: https://squidfunk.github.io/mkdocs-material/
[pre-commit-config]: .pre-commit-config.yaml
[pre-commit-hooks]: https://github.com/pre-commit/pre-commit-hooks
[prettier]: https://prettier.io/
[template-repo]: https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository
Parts derived from the Slack's Bolt for Python template app are licensed under the [MIT License](https://github.com/slack-samples/bolt-python-starter-template/blob/main/LICENSE).