Skip to content

Commit

Permalink
Add CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkbatya committed Jul 25, 2024
1 parent c20ff3a commit 65b5c76
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: 'Deploy'

on:
push:
branches:
- dev
tags:
- '*'
pull_request:

env:
IMAGE_NAME: "flipperdevices/ext-ip-local-port"

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: 'Checkout code'
uses: actions/checkout@v4

- name: 'Set image tag and name'
id: tag
run: |
IMAGE_TAG="0.0.0"
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
REF=${{ github.ref }};
TAG_FULL=${REF#refs/*/};
IMAGE_TAG=${TAG_FULL//\//_};
fi
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: 'Login to Docker Hub'
uses: docker/login-action@v3
with:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: 'Set up Docker Buildx'
uses: docker/setup-buildx-action@v3

- name: 'Build'
uses: docker/build-push-action@v6
with:
push: false
tags: ${{ steps.tag.outputs.image_name }}:${{ steps.tag.outputs.image_tag }}
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache

- name: 'Push'
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.tag.outputs.image_name }}:${{ steps.tag.outputs.image_tag }}
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache
cache-to: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache,mode=max

- name: 'Trigger k8s to use new image: prod'
if: ${{ (github.event_name != 'pull_request')
&& (steps.tag.outputs.image_tag != '0.0.0')
&& (!endsWith(github.event.client_payload.image_tag, '-rc')) }}
uses: peter-evans/repository-dispatch@v3
with:
repository: ${{ secrets.INFRASTRUCTURE_REPO }}
token: ${{ secrets.K8S_GITHUB_PAT }}
event-type: ext-ip-local-port-deploy
client-payload: '{"image_tag": "${{steps.tag.outputs.image_tag}}"}'
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Ext IP local access

## Description
This app can be used for external access local PC http ports

## How to use
1. Create a ZeroTier network. Probably you wanna restrict an inter-network cross-client access ([docs](https://docs.zerotier.com/faq-rules/#client-isolation))
2. Setup this app to be a zerotier network gateway:
1. Generate identity via:
```bash
zerotier-idtool generate gateway.secret gateway.public
```
2. Manualy add member with id from public or secret file (id is the same in both files), example
```bash
$ zerotier-idtool generate gateway.secret gateway.public
gateway.secret written
gateway.public written
$ cat gateway.public
4a7f049cf1:0:a4ee328392ccaf0c22900606aeb20a9cdc76716da70[OMMITED]
```
`4a7f049cf1` will be host ID in this case
3. Assign an IP address to this host via admin console
3. Create a config file, example:
```json
{
"zerotier_network": "ZeroTier network ID",
"zerotier_public_key": "gateway.public output from exaple above",
"zerotier_private_key": "gateway.secret output from exaple above",
"hostname_base": "set a base hostname, eq: 'ext.example.com'",
"users": [ # put all users here
{
"hostname": "prefix to base hostname, eq: 'user1'. It will produce 'user1.ext.example.com' address",
"ip": "user ZeroTier IP address for proxy external traffic to. Eq: 10.10.10.2 for 10.10.10.0/24 net"
}
]
}
```

4. Start a container with the app
```bash
docker run \
--name ext-ip \ # optional
-v $(pwd)/config.json:/etc/app/config.json \
--cap-add NET_ADMIN \
--device /dev/net/tun \
flipperdevices/ext-ip-local-port:0.0.1 # this should be a latest release from github
```

For Kubernetes use you also need to add capabilities [docs](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/)

5. Join a network from clients, also set a coresponding IP's
In example above URL `user1.ext.example.com` will point to the `10.10.10.2` address.

0 comments on commit 65b5c76

Please sign in to comment.