Skip to content

Commit 474b4da

Browse files
committed
Added devcontainer
1 parent 7f3d215 commit 474b4da

10 files changed

Lines changed: 113 additions & 53 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM debian:latest
2+
3+
RUN apt-get update
4+
5+
##
6+
# git
7+
##
8+
9+
RUN apt-get install -y git nano
10+
11+
##
12+
# srt
13+
##
14+
15+
ARG SRT_VERSION
16+
17+
RUN apt-get install -y \
18+
build-essential \
19+
tclsh \
20+
cmake \
21+
pkg-config \
22+
libssl-dev
23+
24+
RUN mkdir -p /opt/srt \
25+
&& git clone https://github.com/Haivision/srt /opt/srt/src \
26+
&& cd /opt/srt/src \
27+
&& git checkout ${SRT_VERSION}
28+
29+
RUN cd /opt/srt/src \
30+
&& ./configure --prefix=.. \
31+
&& make \
32+
&& make install
33+
34+
##
35+
# go
36+
##
37+
38+
ARG GO_VERSION
39+
40+
RUN apt-get install -y wget
41+
RUN <<_EOF_ sh
42+
arch=$(dpkg --print-architecture)
43+
goArch="amd64"
44+
case \${arch} in
45+
arm64) goArch="arm64" ;;
46+
esac
47+
wget -O /tmp/go.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-\${goArch}.tar.gz
48+
tar -C /opt -xzf /tmp/go.tar.gz
49+
_EOF_
50+
ENV PATH="$PATH:/opt/go/bin"

.devcontainer/devcontainer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"build": {
3+
"args": {
4+
"SRT_VERSION": "v1.5.3",
5+
"GO_VERSION": "1.25.3"
6+
},
7+
"dockerfile": "Dockerfile"
8+
},
9+
"containerEnv": {
10+
"CGO_LDFLAGS": "-L/opt/srt/lib/",
11+
"CGO_CFLAGS": "-I/opt/srt/include/",
12+
"LD_LIBRARY_PATH": "/opt/srt/lib",
13+
"PKG_CONFIG_PATH": "/opt/srt/lib/pkgconfig"
14+
},
15+
"customizations": {
16+
"vscode": {
17+
"extensions": [
18+
"ms-vscode.cpptools-extension-pack",
19+
"golang.go"
20+
],
21+
"settings": {
22+
"remote.autoForwardPorts": false
23+
}
24+
}
25+
},
26+
"mounts": [
27+
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/root/.ssh,readonly,type=bind"
28+
],
29+
"name": "asticode/go-astisrt"
30+
}

.github/workflows/test.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches: [ "master", "test-github-actions" ]
66
pull_request:
77
branches: [ "master" ]
88

@@ -11,8 +11,7 @@ jobs:
1111
test:
1212
strategy:
1313
matrix:
14-
# Use macos-latest once latest version is compatible with libsrt
15-
os: [ubuntu-latest, macos-13]
14+
os: [ubuntu-latest, macos-latest]
1615

1716
env:
1817
LIBSRT_VERSION: v1.5.3
@@ -41,7 +40,14 @@ jobs:
4140
- if: ${{ steps.cache-libsrt.outputs.cache-hit != 'true' }}
4241
name: Install libsrt
4342
run: |
44-
make install-srt srcPath=${{ env.LIBSRT_PATH }}/src version=${{ env.LIBSRT_VERSION }}
43+
mkdir -p ${{ env.LIBSRT_PATH }}/src
44+
cd ${{ env.LIBSRT_PATH }}/src
45+
git clone https://github.com/Haivision/srt .
46+
git checkout ${{ env.LIBSRT_VERSION }}
47+
brew update cmake
48+
./configure --prefix=..
49+
make
50+
make install
4551
4652
- name: Set environment variables
4753
run: |

.vscode/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
settings.json

.vscode/c_cpp_properties.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"configurations": [
3+
{
4+
"includePath": [
5+
"${workspaceFolder}/**",
6+
"/opt/srt/include"
7+
]
8+
}
9+
],
10+
"version": 4
11+
}

Makefile

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
version = "v1.5.3"
2-
srcPath = "tmp/$(version)/src"
3-
currentDir := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
4-
5-
install-srt:
6-
rm -rf $(srcPath)
7-
mkdir -p $(srcPath)
8-
# cd $(srcPath) is necessary for windows build since otherwise git doesn't clone in the proper dir
9-
cd $(srcPath) && git clone https://github.com/Haivision/srt .
10-
cd $(srcPath) && git checkout $(version)
11-
cd $(srcPath) && ./configure --prefix=.. $(configure)
12-
cd $(srcPath) && make
13-
cd $(srcPath) && make install
14-
151
generate:
162
go run internal/cmd/generate/options/main.go
173
go run internal/cmd/generate/static_consts/main.go
184
go run internal/cmd/generate/stats/main.go
19-
go run internal/cmd/generate/wrap/main.go
20-
21-
test-coverage:
22-
go test -coverprofile cover.out github.com/asticode/go-astisrt/pkg
23-
go tool cover -html=cover.out
24-
25-
test-linux-build:
26-
cd testdata/linux && docker build -t astisrt-test-linux .
27-
28-
test-linux:
29-
docker run -v ${currentDir}/testdata/linux/gocache:/opt/astisrt/tmp/linux/gocache -v ${currentDir}/testdata/linux/gopath:/opt/astisrt/tmp/linux/gopath -v ${currentDir}:/opt/astisrt/tmp/linux/gopath/src/github.com/asticode/go-astisrt astisrt-test-linux
5+
go run internal/cmd/generate/wrap/main.go

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,6 @@ s.Close()
249249

250250
You can find the instructions to install `srtlib` [here](https://github.com/Haivision/srt/tree/master/docs/build).
251251

252-
However if you don't feel like doing it manually you can use the following command:
253-
254-
```sh
255-
$ make install-srt
256-
```
257-
258-
`srtlib` will be built from source in a directory named `tmp` and located in you working directory.
259-
260252
For your GO code to pick up `srtlib` dependency automatically, you'll need to add the following environment variables:
261253

262254
(don't forget to replace `{{ path to your working directory }}` with the absolute path to your working directory)

internal/cmd/generate/options/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"unicode"
1414
)
1515

16-
const version = "v1.5.3"
17-
1816
var (
1917
r1 = regexp.MustCompile("\\[`([\\w]+)`\\]")
2018
r2 = regexp.MustCompile("`([\\w]+)`")
@@ -280,7 +278,7 @@ func main() {
280278
log.Fatal(fmt.Errorf("main: getting working directory failed: %w", err))
281279
}
282280

283-
opts, enums, err := options(dir)
281+
opts, enums, err := options()
284282
if err != nil {
285283
log.Fatal(fmt.Errorf("main: getting options failed: %w", err))
286284
}
@@ -312,10 +310,10 @@ const (
312310
optionFilePositionEnum
313311
)
314312

315-
func options(dir string) (opts []option, enums []enum, err error) {
313+
func options() (opts []option, enums []enum, err error) {
316314
// Open doc
317315
var f *os.File
318-
if f, err = os.Open(filepath.Join(dir, "tmp", version, "src", "docs", "API", "API-socket-options.md")); err != nil {
316+
if f, err = os.Open("/opt/srt/src/docs/API/API-socket-options.md"); err != nil {
319317
err = fmt.Errorf("main: opening doc failed: %w", err)
320318
return
321319
}
@@ -386,7 +384,7 @@ scan:
386384

387385
// Read header
388386
var b []byte
389-
if b, err = os.ReadFile(filepath.Join(dir, "tmp", version, "include", "srt", "srt.h")); err != nil {
387+
if b, err = os.ReadFile("/opt/srt/include/srt/srt.h"); err != nil {
390388
err = fmt.Errorf("main: reading header failed: %w", err)
391389
return
392390
}

internal/cmd/generate/static_consts/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"text/template"
1111
)
1212

13-
const version = "v1.5.3"
14-
1513
var r = regexp.MustCompile(`\nstatic const ([^ ]+) ([^ ]+) =`)
1614

1715
type staticConst struct {
@@ -53,7 +51,7 @@ func main() {
5351
log.Fatal(fmt.Errorf("main: getting working directory failed: %w", err))
5452
}
5553

56-
cs, err := staticConsts(dir)
54+
cs, err := staticConsts()
5755
if err != nil {
5856
log.Fatal(fmt.Errorf("main: getting stats failed: %w", err))
5957
}
@@ -73,10 +71,10 @@ func main() {
7371
}
7472
}
7573

76-
func staticConsts(dir string) (cs []staticConst, err error) {
74+
func staticConsts() (cs []staticConst, err error) {
7775
// Read header
7876
var b []byte
79-
if b, err = os.ReadFile(filepath.Join(dir, "tmp", version, "include", "srt", "srt.h")); err != nil {
77+
if b, err = os.ReadFile("/opt/srt/include/srt/srt.h"); err != nil {
8078
err = fmt.Errorf("main: reading header failed: %w", err)
8179
return
8280
}

internal/cmd/generate/stats/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"unicode"
1414
)
1515

16-
const version = "v1.5.3"
17-
1816
var r1 = regexp.MustCompile(`struct CBytePerfMon\n\{([^\}]*)`)
1917
var r2 = regexp.MustCompile(`[\s]*([\w]+)[\s]*([\w]+);`)
2018

@@ -119,7 +117,7 @@ func main() {
119117
log.Fatal(fmt.Errorf("main: getting working directory failed: %w", err))
120118
}
121119

122-
ss, err := stats(dir)
120+
ss, err := stats()
123121
if err != nil {
124122
log.Fatal(fmt.Errorf("main: getting stats failed: %w", err))
125123
}
@@ -139,10 +137,10 @@ func main() {
139137
}
140138
}
141139

142-
func stats(dir string) (ss []stat, err error) {
140+
func stats() (ss []stat, err error) {
143141
// Read header
144142
var b []byte
145-
if b, err = os.ReadFile(filepath.Join(dir, "tmp", version, "include", "srt", "srt.h")); err != nil {
143+
if b, err = os.ReadFile("/opt/srt/include/srt/srt.h"); err != nil {
146144
err = fmt.Errorf("main: reading header failed: %w", err)
147145
return
148146
}

0 commit comments

Comments
 (0)