Skip to content

Commit

Permalink
ci: add GitHub Actions pipeline automated versioning and publishing (#…
Browse files Browse the repository at this point in the history
…104)

* Added github action for publishing docker images

* Added github action for publishing docker images

* Updated docker up repo name

* Upgraded to action build-push-action@v2

* Upgraded to action build-push-action@v2

* Correctly logging into github registry

* Added prepare step and setting imgage labels

* Pushing image to GHCR and Docker Hub

* Docker publish 'needs' tests to be run

* Only running docker pipeline on master

* ci: join docker build and go tests to one ci pipeline

* ci: move docker release to dedicated ci pipeline and triggering pipeline on new version tags

* docs: add hint for developers to use conventional commits

* fix(ci): never push images during build job

* fix(ci): change docker release trigger to run on creation of version tags

See actions/runner#1007

* fix(ci): change docker release trigger to run on creation and push of version tags

See actions/runner#1007 and https://github.com/docker/metadata-action#basic

* fix(ci): release branch is master not main

* fix(ci): run workflow anytime someone creates a branch or tag

See: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#create

* ci: use GitHubActions cache for docker images

* ci: move docker release to test-build-release.yml and use semver tag for images

* ci: setup buildx in release

* ci: push to GHCR on release add pre-release option for releases

* ci: push to GHCR on release add pre-release option for releases

* ci: add push to DuckerHub

* ci: no organization prefix for docker hub

* ci: move go release to test-build-release.yml so that artifacts can be included in GitHub release

* ci: fix go releaser version

* ci: keep dist and setting git tag before goreleaser

* ci: keep dist and setting git tag before goreleaser

* ci: provide commit ref for release instead of tag

* ci: use both tag and commit ref

* ci: remove git tag after go release

* ci: create release from conventional commit change loge before running gorelease

* ci: set tag before gorelease

* ci: delete release-go.yml

* ci: pre-release tag for github release

* ci: checking release_type for tagging as prerelease indicator

* ci: fix version of ncipollo/release-action

* ci: setup buildx in release

* ci: push to GHCR on release add pre-release option for releases

* ci: add push to DuckerHub

* ci: no organization prefix for docker hub

* ci: move go release to test-build-release.yml so that artifacts can be included in GitHub release

* ci: fix go releaser version

* ci: keep dist and setting git tag before goreleaser

* ci: keep dist and setting git tag before goreleaser

* ci: provide commit ref for release instead of tag

* ci: use both tag and commit ref

* ci: remove git tag after go release

* ci: create release from conventional commit change loge before running gorelease

* ci: set tag before gorelease

* ci: delete release-go.yml

* ci: pre-release tag for github release

* ci: checking release_type for tagging as prerelease indicator

* ci: fix version of ncipollo/release-action

* ci: also run test and build on PRs into 'pre-release'

Co-authored-by: Konstantin Strümpf <33258365+SirPumpkinHead@users.noreply.github.com>
  • Loading branch information
kstruempf and kstruempf authored Feb 14, 2022
1 parent e1d8ae9 commit 51cd0f2
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 49 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/release.yml

This file was deleted.

140 changes: 140 additions & 0 deletions .github/workflows/test-build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Test, Build, Release

on:
push:
branches: [ 'master', 'pre-release' ]
pull_request:
branches: [ 'master', 'dev', 'pre-release' ]

env:
GH_REGISTRY: ghcr.io
REPOSITORY_NAME: ${{ github.repository }}

jobs:

# Build job runs on every PR into dev and master and pushes to master
test:
name: Test
strategy:
matrix:
go-version: [ 1.16.x ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test ./...

# Build job runs on every PR into dev and master and pushes to master
# Depends on test job
build-docker:
runs-on: ubuntu-latest
name: Build
needs: [ test ]
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Build Docker Images
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
pull: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Release job runs on every push to master
# Depends on build job
release-docker:
runs-on: ubuntu-latest
name: Release
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/pre-release' }}
needs: [ build-docker ]
steps:
- name: Checkout repository
uses: actions/checkout@v2

# Create semver tag and changelog
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: master
pre_release_branches: pre-release

# Build Docker Images for GHCR
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ env.GH_REGISTRY }}/${{ env.REPOSITORY_NAME }}
${{ env.REPOSITORY_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ steps.tag_version.outputs.new_tag }}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.GH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push version ${{ steps.tag_version.outputs.new_tag }}
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max

# Create GitHub release once images have been pushed
- name: Create a GitHub release ${{ steps.tag_version.outputs.new_tag }}
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
prerelease: contains( ${{ steps.tag_version.outputs.release_type }} , 'pre' )

# Build Go Release
- run: git tag ${{ steps.tag_version.outputs.new_tag }}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Run GoReleaser ${{ steps.tag_version.outputs.new_tag }}
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release
workdir: ./cmd/infrared/.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 0 additions & 18 deletions .github/workflows/test.yml

This file was deleted.

39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ $ docker build --no-cache -t haveachin/infrared:latest https://github.com/haveac
`./infrared -config-path="." -receive-proxy-protocol=true -enable-prometheus -prometheus-bind="localhost:9123"`

## Proxy Config

| Field Name | Type | Required | Default | Description |
|-------------------|---------|----------|------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| domainName | String | true | localhost | Should be [fully qualified domain name](https://en.wikipedia.org/wiki/Domain_name). <br>Note: Every string is accepted. So `localhost` is also valid. |
Expand Down Expand Up @@ -135,7 +134,6 @@ More info on [Portainer](https://www.portainer.io/).
| url | String | true | | URL of the callback server URL. |
| events | Array | true | | A string array of event names. Currently available event names are:<br>- `Error` will send error logs<br>- `PlayerJoin` will send player joins<br>- `PlayerLeave` will send player leaves<br>- `ContainerStart` will send container starts<br>- `ContainerStop` will send container stops |


### Examples

#### Minimal Config
Expand Down Expand Up @@ -218,13 +216,16 @@ More info on [Portainer](https://www.portainer.io/).
</details>

## Rest API

**The API should not be accessible from the internet!**

### Enabling API
To enable the API the environment variable `INFRARED_API_ENABLED` must be set to `"true"`.
To change the http bind, set the env variable `INFRARED_API_BIND` to something like `"0.0.0.0:3000"` the default value is `"127.0.0.1:8080"`

To enable the API the environment variable `INFRARED_API_ENABLED` must be set to `"true"`. To change the http bind, set
the env variable `INFRARED_API_BIND` to something like `"0.0.0.0:3000"` the default value is `"127.0.0.1:8080"`

### API Methods

#### Create new config

POST `/proxies`\
Expand Down Expand Up @@ -283,6 +284,36 @@ scrape_configs:
* **instance:** what infrared instance has that amount of active proxies.
* **job:** what job was specified in the prometheus configuration.

## Coding Guidelines

### Commit Messages

When contributing to this project please follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
specification for writing commit messages, so that changelogs and release versions can be generated automatically.

**Example commit message**

```
fix: prevent racing of requests

Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.

Remove timeouts which were used to mitigate the racing issue but are
obsolete now.

Reviewed-by: Z
Refs: #123
```
Some tooling that can help you author those commit messages are the following plugins:
* JetBrains Plugin [Conventional Commit](https://plugins.jetbrains.com/plugin/13389-conventional-commit)
by [Edoardo Luppi](https://github.com/lppedd)
* Visual Studio
Plugin [Conventional Commits](https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits)
by [vivaxy](https://marketplace.visualstudio.com/publishers/vivaxy)
## Similar Projects
* https://github.com/itzg/mc-router

0 comments on commit 51cd0f2

Please sign in to comment.