Skip to content

Commit 0c3e667

Browse files
committed
separate infra and app code workflows
1 parent 464ef8d commit 0c3e667

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Pulumi
2+
on:
3+
pull_request:
4+
paths-ignore:
5+
- infra/**
6+
- .github/workflows/pull_request_infra.yml
7+
jobs:
8+
preview:
9+
name: Pulumi Preview
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: "read"
13+
id-token: "write"
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: "google-github-actions/auth@v2"
17+
with:
18+
project_id: "osakunta"
19+
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
20+
- run: pip install -r requirements.txt
21+
- uses: pulumi/actions@v6
22+
with:
23+
command: preview
24+
stack-name: prod
25+
cloud-url: ${{ secrets.PULUMI_CLOUD_URL }}

.github/workflows/pull_request.yml renamed to .github/workflows/pull_request_infra.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Pulumi
22
on:
3-
- pull_request
3+
pull_request:
4+
paths:
5+
- infra/**
6+
- .github/workflows/pull_request_infra.yml
47
jobs:
58
preview:
69
name: Pulumi Preview

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
SatO Telegram Bot
2-
=================
1+
# SatO Telegram Bot
32

43
This bot has some useful functionality for Satakuntalainen Osakunta. It can be found on Telegram as `@osakuntabot`.
54

@@ -10,9 +9,27 @@ Available commands:
109
/ruokalista
1110
/tjviisi
1211

12+
## Development
1313

14-
Development
15-
-----------
14+
⚠️⚠️ Read the entirety of this section before making changes to the repository ⚠️⚠️
15+
16+
### Development flow
17+
18+
1. Always create a new branch for whatever you are working on
19+
2. When you're done, create a pull request
20+
3. Check the preview for what changes will be done upon deployment
21+
4. If everything looks good, merge the pull request and the changes will be automatically done
22+
23+
### Warnings
24+
25+
The code in the `master` branch is automatically deployed. Therefore you should be careful as to what you merge to this branch.
26+
27+
Changes to the `infra/` directory modify the resources that are deployed on the cloud. These can incur extra cost if you are not careful.
28+
Changes to the application source code (`main.py`, `telegram_bot/`) can also incur costs if they run for long or consume a lot of resources (processor time, bandwidth)
29+
30+
Be mindful to the changes you make. You can ask for help and comments on your pull request before merging. After large changes, monitor the costs incurred manually on the cloud dashboard.
31+
32+
### Local development
1633

1734
Get `pipenv` from [here](https://pipenv.pypa.io/en/latest/)
1835

@@ -30,5 +47,4 @@ You can test the commands on commandline by:
3047

3148
python main.py /command [args]
3249

33-
The bot is hosted in Google Cloud Functions and CircleCI is used to continuously deploy new versions of the bot to GCP.
34-
NB! If you add dependencies to the project, remember to generate a new requirements.txt with `pipenv lock -r` and push it to the repo. Pipfile is not supported by Google Cloud Functions.
50+
NB! If you add dependencies to the project, remember to generate a new requirements.txt with `pipenv requirements > requirements.txt` and push it to the repo. Pipfile is not supported by Google Cloud Functions.

infra/__main__.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
1-
"""A Python Pulumi program"""
2-
31
import pulumi
42
import pulumi_gcp as gcp
5-
import tarfile
6-
import hashlib
7-
8-
# create .tar.gz source
9-
10-
# SOURCE_TAR_NAME = "source.tar.gz"
11-
12-
# tarfile_hash = None
13-
# with tarfile.open(SOURCE_TAR_NAME, "w|gz") as tar:
14-
# tar.add("../telegram_bot", arcname="telegram_bot")
15-
# tar.add("../main.py", arcname="main.py")
16-
# tar.add("../requirements.txt", arcname="requirements.txt")
17-
# last_modified = max([member.mtime for member in tar.getmembers()])
18-
# tarfile_hash = hashlib.sha256(str(last_modified).encode()).hexdigest()
193

4+
# Be careful editing this file, if you are unfamiliar with Pulumi or the Google Cloud Platform.
5+
# Make sure you read the README.md in the root of this repository first.
206

217
# setup infrastructure
228

239
PROJECT_ID = "osakunta-telegram-bot"
2410
LOCATION = "europe-north1"
2511

26-
2712
# Set up secret to hold the Telegram API token
2813
telegram_bot_token = gcp.secretmanager.Secret("telegram-bot-token",
2914
secret_id="telegram-bot-token",
@@ -102,5 +87,4 @@
10287
name=function.name,
10388
role="roles/run.invoker",
10489
member="allUsers"
105-
)
106-
90+
)

0 commit comments

Comments
 (0)