Skip to content

Commit

Permalink
Add Github actions CI/CD (#42)
Browse files Browse the repository at this point in the history
* Add ci/cd GH actions

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

Update README.md

Create dockerimage.yml

Add docker CD

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

fixup! Add docker CD

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

Fix Goreleaser

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

FIX CD

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

fixup! FIX CD

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

fixup! fixup! FIX CD

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>

fixup! fixup! fixup! FIX CD

Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed May 19, 2020
1 parent 5fea1d9 commit 70152f5
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 70 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CD

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --skip-sign
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI

on:
pull_request:
push:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
- name: Run tests and attempt building
run: |
export PATH=$(go env GOPATH)/bin:$PATH
go test -mod vendor -v -race ./...
go build -mod vendor
29 changes: 29 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Docker Image CI/CD

on:
push:
tags:
- '*'

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag iptv-proxy:$(git describe --abbrev=0 --tags 2>/dev/null)

push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: pierre-emmanuelj/iptv-proxy/iptv-proxy
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
registry: docker.pkg.github.com
14 changes: 0 additions & 14 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ builds:
goarch:
- amd64

sign:
cmd: gpg
args: ["-u", "pierre-emmanuel.jacquier@epitech.eu", "--detach-sign", "${artifact}"]
artifacts: all

archives:
-
format_overrides:
Expand All @@ -42,12 +37,3 @@ nfpms:
formats:
- deb
- rpm

brews:
-
github:
owner: pierre-emmanuel
name: homebrew-tap
folder: Formula
homepage: "https://github.com/pierre-emmanuelJ/iptv-proxy"
description: Reverse proxy on iptv m3u file
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Iptv Proxy

[![Build Status](https://travis-ci.com/pierre-emmanuelJ/iptv-proxy.svg?branch=master)](https://travis-ci.com/pierre-emmanuelJ/iptv-proxy)
[![Actions Status](https://github.com/pierre-emmanuelJ/iptv-proxy/workflows/CI/badge.svg)](https://github.com/pierre-emmanuelJ/iptv-proxy/actions?query=workflow%3ACI)

## Description

Expand Down
24 changes: 12 additions & 12 deletions pkg/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *Config) getM3U(ctx *gin.Context) {
func (c *Config) reverseProxy(ctx *gin.Context) {
rpURL, err := url.Parse(c.track.URI)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}

Expand All @@ -59,15 +59,15 @@ func (c *Config) stream(ctx *gin.Context, oriURL *url.URL) {

resp, err := http.Get(oriURL.String())
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}
defer resp.Body.Close()

copyHTTPHeader(ctx, resp.Header)
ctx.Status(resp.StatusCode)
ctx.Stream(func(w io.Writer) bool {
io.Copy(w, resp.Body)
io.Copy(w, resp.Body) // nolint: errcheck
return false
})
}
Expand All @@ -81,15 +81,15 @@ func (c *Config) hlsStream(ctx *gin.Context, oriURL *url.URL) {

resp, err := client.Get(oriURL.String())
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusFound {
location, err := resp.Location()
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}
id := ctx.Param("id")
Expand All @@ -100,22 +100,22 @@ func (c *Config) hlsStream(ctx *gin.Context, oriURL *url.URL) {

hlsResp, err := http.Get(location.String())
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}
defer hlsResp.Body.Close()

b, err := ioutil.ReadAll(hlsResp.Body)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}
body := string(b)
body = strings.ReplaceAll(body, "/"+c.XtreamUser.String()+"/"+c.XtreamPassword.String()+"/", "/"+c.User.String()+"/"+c.Password.String()+"/")
ctx.Data(http.StatusOK, hlsResp.Header.Get("Content-Type"), []byte(body))
return
}
ctx.AbortWithError(http.StatusInternalServerError, errors.New("Unable to HLS stream"))
ctx.AbortWithError(http.StatusInternalServerError, errors.New("Unable to HLS stream")) // nolint: errcheck
return
}

Expand All @@ -137,7 +137,7 @@ type authRequest struct {
func (c *Config) authenticate(ctx *gin.Context) {
var authReq authRequest
if err := ctx.Bind(&authReq); err != nil {
ctx.AbortWithError(http.StatusBadRequest, err)
ctx.AbortWithError(http.StatusBadRequest, err) // nolint: errcheck
return
}
if c.ProxyConfig.User.String() != authReq.Username || c.ProxyConfig.Password.String() != authReq.Password {
Expand All @@ -148,17 +148,17 @@ func (c *Config) authenticate(ctx *gin.Context) {
func (c *Config) appAuthenticate(ctx *gin.Context) {
contents, err := ioutil.ReadAll(ctx.Request.Body)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}

q, err := url.ParseQuery(string(contents))
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}
if len(q["username"]) == 0 || len(q["password"]) == 0 {
ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("bad body url query parameters"))
ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("bad body url query parameters")) // nolint: errcheck
return
}
log.Printf("[iptv-proxy] %v | %s |App Auth\n", time.Now().Format("2006/01/02 - 15:04:05"), ctx.ClientIP())
Expand Down
18 changes: 10 additions & 8 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func NewServer(config *config.ProxyConfig) (*Config, error) {

// Serve the iptv-proxy api
func (c *Config) Serve() error {
c.playlistInitialization()
if err := c.playlistInitialization(); err != nil {
return err
}

router := gin.Default()
router.Use(cors.Default())
Expand All @@ -93,25 +95,25 @@ func (c *Config) playlistInitialization() error {

// MarshallInto a *bufio.Writer a Playlist.
func (c *Config) marshallInto(into *os.File, xtream bool) error {
into.WriteString("#EXTM3U\n")
into.WriteString("#EXTM3U\n") // nolint: errcheck
for _, track := range c.playlist.Tracks {
into.WriteString("#EXTINF:")
into.WriteString(fmt.Sprintf("%d ", track.Length))
into.WriteString("#EXTINF:") // nolint: errcheck
into.WriteString(fmt.Sprintf("%d ", track.Length)) // nolint: errcheck
for i := range track.Tags {
if i == len(track.Tags)-1 {
into.WriteString(fmt.Sprintf("%s=%q", track.Tags[i].Name, track.Tags[i].Value))
into.WriteString(fmt.Sprintf("%s=%q", track.Tags[i].Name, track.Tags[i].Value)) // nolint: errcheck
continue
}
into.WriteString(fmt.Sprintf("%s=%q ", track.Tags[i].Name, track.Tags[i].Value))
into.WriteString(fmt.Sprintf("%s=%q ", track.Tags[i].Name, track.Tags[i].Value)) // nolint: errcheck
}
into.WriteString(", ")
into.WriteString(", ") // nolint: errcheck

uri, err := c.replaceURL(track.URI, xtream)
if err != nil {
return err
}

into.WriteString(fmt.Sprintf("%s\n%s\n", track.Name, uri))
into.WriteString(fmt.Sprintf("%s\n%s\n", track.Name, uri)) // nolint: errcheck
}

return into.Sync()
Expand Down
Loading

0 comments on commit 70152f5

Please sign in to comment.