Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattwelke/github-actions-pubsub-emulator-example
https://github.com/mattwelke/github-actions-pubsub-emulator-example
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/mattwelke/github-actions-pubsub-emulator-example
- Owner: mattwelke
- Created: 2022-02-07T18:02:21.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-21T16:16:09.000Z (over 2 years ago)
- Last Synced: 2024-10-14T02:24:12.895Z (3 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# github-actions-pubsub-emulator-example
GCP makes an emulator available for the Pub/Sub service. They do this by providing it as a gcloud component that you are meant to use (https://cloud.google.com/pubsub/docs/emulator).
In GitHub Actions, when you have a use case where you want to run something in the background throughout your workflow, like running the Pub/Sub emulator for tests, you'd normally use services (https://docs.github.com/en/actions/using-containerized-services/about-service-containers). GitHub made this feature with this use case in mind.
Unfortunately, right now, the services feature of workflows does not support overriding the command used to start the image used for the service. It can only start images with their default entry points. Their docs includes a Postgres example where this works fine:
```yaml
# Service containers to run with `runner-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
```This means that to use the Pub/Sub emulator in a workflow, we must manually start it in a step, keeping it running in the background throughout the rest of the workflow. At the end of the workflow, the runner will automatically shut it down.
Example:
```yaml
- name: 'Start Pub/Sub emulator'
run: |
gcloud beta emulators pubsub start --host-port=0.0.0.0:8085 &
```For the full example, see `.github/workflows/use_pubsub_emulator.yml` in this repo.