Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 8a3d3c0

Browse files
initial commit
0 parents  commit 8a3d3c0

File tree

10 files changed

+231
-0
lines changed

10 files changed

+231
-0
lines changed

.github/release-drafter.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name-template: 'v$RESOLVED_VERSION 🌈'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
categories:
4+
- title: '🚀 Features'
5+
labels:
6+
- 'feat'
7+
- title: '🐛 Bug Fixes'
8+
labels:
9+
- 'fix'
10+
- 'refactor'
11+
- title: '🧰 Maintenance'
12+
labels:
13+
- 'chore'
14+
- title: '📦 dependencies'
15+
labels:
16+
- 'dependencies'
17+
change-template: '- $TITLE (#$NUMBER) by @$AUTHOR'
18+
change-title-escapes: '\<*_&'
19+
autolabeler:
20+
- label: feat
21+
title:
22+
- '/^feat:.+/'
23+
- label: fix
24+
title:
25+
- '/^fix:.+/'
26+
- label: refactor
27+
title:
28+
- '/^refactor:.+/'
29+
- label: chore
30+
title:
31+
- '/^chore:.+/'
32+
- '/^chore\(deps\):.+/'
33+
- label: dependencies
34+
title:
35+
- '/chore\(deps\)[/-].+/'
36+
- '/fix\(deps\)[/-].+/'
37+
version-resolver:
38+
major:
39+
labels:
40+
- 'major'
41+
minor:
42+
labels:
43+
- 'minor'
44+
patch:
45+
labels:
46+
- 'patch'
47+
default: patch
48+
template: |
49+
## Changes
50+
51+
$CHANGES

.github/workflows/cache.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Cache
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
workflow_dispatch:
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-cache
9+
cancel-in-progress: true
10+
jobs:
11+
clean:
12+
name: clean
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: mokmok-dev/delete-actions-cache@v0.1.0
17+
env:
18+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/push.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Push
2+
on:
3+
push:
4+
branches:
5+
- "**"
6+
tags:
7+
- "v*.*.*"
8+
workflow_dispatch:
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}-push
11+
cancel-in-progress: true
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: docker/metadata-action@v4
18+
id: meta
19+
with:
20+
images: ghcr.io/mokmok-dev/gcloud-pubsub-push-emulator
21+
tags: |
22+
type=raw,value=latest
23+
type=semver,pattern={{version}}
24+
type=sha,format=short,prefix=
25+
- name: Login GitHub Packages
26+
uses: docker/login-action@v2.1.0
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
- uses: docker/setup-buildx-action@v2
32+
- uses: docker/build-push-action@v4.0.0
33+
with:
34+
context: .
35+
push: true
36+
tags: ${{ steps.meta.outputs.tags }}
37+
labels: ${{ steps.meta.outputs.labels }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Release
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
workflow_dispatch:
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-release
9+
cancel-in-progress: true
10+
jobs:
11+
draft:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: release-drafter/release-drafter@v5
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax=docker/dockerfile:1.3
2+
FROM curlimages/curl:latest as fetcher
3+
4+
ARG WAITFOR_VERSION=2.2.4
5+
RUN curl -vsSLo /tmp/wait-for "https://github.com/eficode/wait-for/releases/download/v${WAITFOR_VERSION}/wait-for"
6+
RUN chmod +x /tmp/wait-for
7+
8+
FROM google/cloud-sdk:444.0.0
9+
10+
ENV PYTHONDONTWRITEBYTECODE=1
11+
ENV PYTHONUNBUFFERED=1
12+
13+
COPY --from=fetcher /tmp/wait-for /usr/bin
14+
COPY pubsub.py /usr/bin/pubsub
15+
COPY run.sh /run.sh
16+
17+
EXPOSE 8681 8682/udp
18+
19+
ENTRYPOINT ["./run.sh"]

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2020, marcel corso gonzalez
4+
Copyright (c) 2021, Kevin James
5+
Copyright (c) 2023, mokmok.dev
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
13+
2. Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
3. Neither the name of the copyright holder nor the names of its
18+
contributors may be used to endorse or promote products derived from
19+
this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# gcloud-pubsub-push-emulator
2+
3+
This image is clone of [TheKevJames/docker-gcloud-pubsub-emulator](https://github.com/TheKevJames/tools/tree/master/docker-gcloud-pubsub-emulator).

pubsub.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import subprocess
6+
7+
def main() -> None:
8+
i = 0
9+
while True:
10+
i += 1
11+
env = os.environ.get(f"PUBSUB_PROJECT{i}")
12+
if not env:
13+
if i == 1:
14+
print('$PUBSUB_PROJECT1 was not set')
15+
sys.exit(1)
16+
return
17+
18+
project, *topics = env.split(',')
19+
if not topics:
20+
print(f'ERROR: $PUBSUB_PROJECT{i} had no defined topic')
21+
sys.exit(1)
22+
23+
for topic in topics:
24+
# create topic
25+
print(f"python3 publisher.py {project} create {topic}")
26+
27+
topic, *subscription = topic.split(':')
28+
if subscription:
29+
subscription, *endpoint = subscription
30+
if subscription and endpoint:
31+
# create topic with push endpoint
32+
print(f"python3 subscriber.py {project} create-push {topic} {subscription} {endpoint[0]}")
33+
if subscription and not endpoint:
34+
# create topic with subscription
35+
print(f"python3 subscriber.py {project} create {topic} {subscription}")
36+
37+
if __name__ == '__main__':
38+
main()

renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:base"
5+
]
6+
}

run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
(
4+
set -eu
5+
echo "Waiting for emulator..."
6+
/usr/bin/wait-for localhost:8681 -- env PUBSUB_EMULATOR_HOST=localhost:8681 /usr/bin/pubsub
7+
echo "Done building projects/topics/subscriptions! Opening readiness port..."
8+
nc -lkp 8682
9+
) &
10+
11+
gcloud beta emulators pubsub start --host-port=0.0.0.0:8681 "$@"

0 commit comments

Comments
 (0)