mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-01 00:45:23 +00:00
Handle App not found in purge, + cleanup
* gosuper in dockerignored folder * correctly handle app not found in purge * test formatting in test-gosuper * Fix test-gosuper * DRY up test-integration
This commit is contained in:
parent
53668647c8
commit
9bc2f6212d
@ -9,3 +9,4 @@ coffeelint.json
|
||||
automation
|
||||
tools
|
||||
README.md
|
||||
gosuper
|
||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,7 @@
|
||||
/node_modules/
|
||||
*.swp
|
||||
data
|
||||
gosuper/bin
|
||||
bin/gosuper
|
||||
bin/linux_amd64
|
||||
bin/linux_386
|
||||
bin/linux_arm
|
||||
|
@ -32,8 +32,8 @@ RUN chmod +x /app/src/enterContainer.sh \
|
||||
&& /app/node_modules/.bin/coffee -c /app/src \
|
||||
&& ln -sf /app/entry.sh /start # Needed for legacy
|
||||
|
||||
RUN mv /app/gosuper/bin/linux_amd64/gosuper /app/gosuper/bin/ && \
|
||||
chmod +x /app/gosuper/bin/gosuper
|
||||
RUN mv /app/bin/linux_amd64/gosuper /app/bin/ && \
|
||||
chmod +x /app/bin/gosuper
|
||||
|
||||
ENV SUPERVISOR_IMAGE resin/amd64-supervisor
|
||||
ENV CONFIG_MOUNT_POINT /boot/config.json
|
||||
|
@ -32,8 +32,8 @@ RUN chmod +x /app/src/enterContainer.sh \
|
||||
&& /app/node_modules/.bin/coffee -c /app/src \
|
||||
&& ln -sf /app/entry.sh /start # Needed for legacy
|
||||
|
||||
RUN mv /app/gosuper/bin/linux_arm/gosuper /app/gosuper/bin/ && \
|
||||
chmod +x /app/gosuper/bin/gosuper
|
||||
RUN mv /app/bin/linux_arm/gosuper /app/bin/ && \
|
||||
chmod +x /app/bin/gosuper
|
||||
|
||||
ENV SUPERVISOR_IMAGE resin/armv7hf-supervisor
|
||||
ENV CONFIG_MOUNT_POINT /boot/config.json
|
||||
|
@ -1,14 +0,0 @@
|
||||
FROM golang:1.4.2-cross
|
||||
|
||||
ENV GOOS linux
|
||||
ENV GOPATH /usr/src/app
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY . src/resin-supervisor
|
||||
|
||||
RUN chmod +x src/resin-supervisor/build_gosuper.sh
|
||||
|
||||
# Run go install with -a (force rebuilding of all packages)
|
||||
# and -v (print package names as they are built)
|
||||
CMD cd ./src/resin-supervisor && ./build_gosuper.sh
|
@ -32,8 +32,8 @@ RUN chmod +x /app/src/enterContainer.sh \
|
||||
&& /app/node_modules/.bin/coffee -c /app/src \
|
||||
&& ln -sf /app/entry.sh /start # Needed for legacy
|
||||
|
||||
RUN mv /app/gosuper/bin/linux_386/gosuper /app/gosuper/bin/ && \
|
||||
chmod +x /app/gosuper/bin/gosuper
|
||||
RUN mv /app/bin/linux_386/gosuper /app/bin/ && \
|
||||
chmod +x /app/bin/gosuper
|
||||
|
||||
ENV SUPERVISOR_IMAGE resin/i386-supervisor
|
||||
ENV CONFIG_MOUNT_POINT /boot/config.json
|
||||
|
@ -32,7 +32,7 @@ RUN chmod +x /app/src/enterContainer.sh \
|
||||
&& /app/node_modules/.bin/coffee -c /app/src \
|
||||
&& ln -sf /app/entry.sh /start # Needed for legacy
|
||||
|
||||
RUN mv /app/gosuper/bin/linux_arm/gosuper /app/gosuper/bin/ && \
|
||||
chmod +x /app/gosuper/bin/gosuper
|
||||
RUN mv /app/bin/linux_arm/gosuper /app/bin/ && \
|
||||
chmod +x /app/bin/gosuper
|
||||
|
||||
CMD ["/app/entry.sh"]
|
||||
|
22
Makefile
22
Makefile
@ -36,9 +36,10 @@ run-supervisor: supervisor-dind stop-supervisor
|
||||
&& docker run -d --name resin_supervisor_1 --privileged -v $$(pwd)/config.json:/usr/src/app/config/config.json -v $$(pwd)/config/env:/usr/src/app/config/env -v /sys/fs/cgroup:/sys/fs/cgroup:ro resin/resin-supervisor-dind:$(SUPERVISOR_VERSION)
|
||||
|
||||
stop-supervisor:
|
||||
-docker stop resin_supervisor_1 > /dev/null
|
||||
# Remove volumes to prevent us from running out of loopback devices,
|
||||
# Stop docker and remove volumes to prevent us from running out of loopback devices,
|
||||
# as per https://github.com/jpetazzo/dind/issues/19
|
||||
-docker exec resin_supervisor_1 bash -c "systemctl stop docker"
|
||||
-docker stop resin_supervisor_1 > /dev/null
|
||||
-docker rm -f --volumes resin_supervisor_1 > /dev/null
|
||||
|
||||
supervisor: gosuper
|
||||
@ -52,24 +53,29 @@ deploy: supervisor
|
||||
docker push $(DEPLOY_REGISTRY)$(IMAGE)
|
||||
|
||||
go-builder:
|
||||
-cp tools/dind/config.json .
|
||||
docker build -f Dockerfile.gosuper -t resin/go-supervisor-builder:$(SUPERVISOR_VERSION) .
|
||||
-rm config.json
|
||||
-cp tools/dind/config.json ./gosuper/
|
||||
cd gosuper && docker build -t resin/go-supervisor-builder:$(SUPERVISOR_VERSION) .
|
||||
-rm ./gosuper/config.json
|
||||
|
||||
gosuper: go-builder
|
||||
-mkdir -p gosuper/bin
|
||||
-docker rm --volumes -f resin_build_gosuper_$(JOB_NAME)
|
||||
docker run --name resin_build_gosuper_$(JOB_NAME) -v $(shell pwd)/gosuper/bin:/usr/src/app/bin -e USER_ID=$(shell id -u) -e GROUP_ID=$(shell id -g) -e GOARCH=$(GOARCH) resin/go-supervisor-builder:$(SUPERVISOR_VERSION)
|
||||
docker run --name resin_build_gosuper_$(JOB_NAME) -v $(shell pwd)/bin:/usr/src/app/bin -e USER_ID=$(shell id -u) -e GROUP_ID=$(shell id -g) -e GOARCH=$(GOARCH) resin/go-supervisor-builder:$(SUPERVISOR_VERSION)
|
||||
docker rm --volumes -f resin_build_gosuper_$(JOB_NAME)
|
||||
|
||||
test-gosuper: go-builder
|
||||
-docker rm --volumes -f resin_test_gosuper_$(JOB_NAME)
|
||||
docker run --name resin_test_gosuper_$(JOB_NAME) -v $(shell pwd)/gosuper/bin:/usr/src/app/bin resin/go-supervisor-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor && go test -v ./gosuper"
|
||||
docker run --name resin_test_gosuper_$(JOB_NAME) -v $(shell pwd)/bin:/usr/src/app/bin resin/go-supervisor-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor/gosuper && ./test_formatting.sh && go test -v ./gosuper"
|
||||
docker rm --volumes -f resin_test_gosuper_$(JOB_NAME)
|
||||
|
||||
format-gosuper: go-builder
|
||||
-docker rm --volumes -f resin_test_gosuper_$(JOB_NAME)
|
||||
docker run --name resin_test_gosuper_$(JOB_NAME) -v $(shell pwd)/bin:/usr/src/app/bin -v $(shell pwd)/gosuper:/usr/src/app/src/resin-supervisor/gosuper resin/go-supervisor-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor/gosuper && go fmt ./..."
|
||||
docker rm --volumes -f resin_test_gosuper_$(JOB_NAME)
|
||||
|
||||
test-integration: go-builder
|
||||
-docker rm --volumes -f resin_test_integration_$(JOB_NAME)
|
||||
docker run --name resin_test_integration_$(JOB_NAME) --net=host -e SUPERVISOR_IP="$(shell docker inspect --format '{{ .NetworkSettings.IPAddress }}' resin_supervisor_1)" -v $(shell pwd)/gosuper/bin:/usr/src/app/bin --volumes-from resin_supervisor_1 resin/go-supervisor-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor && go test -v ./supertest"
|
||||
docker run --name resin_test_integration_$(JOB_NAME) --net=host -e SUPERVISOR_IP="$(shell docker inspect --format '{{ .NetworkSettings.IPAddress }}' resin_supervisor_1)" -v $(shell pwd)/bin:/usr/src/app/bin --volumes-from resin_supervisor_1 resin/go-supervisor-builder:$(SUPERVISOR_VERSION) bash -c "cd src/resin-supervisor/gosuper && go test -v ./supertest"
|
||||
docker rm --volumes -f resin_test_integration_$(JOB_NAME)
|
||||
|
||||
.PHONY: supervisor deploy supervisor-dind run-supervisor
|
||||
|
@ -80,6 +80,7 @@ import "github.com/path/to/dependency"
|
||||
```
|
||||
And we save it to Godeps.json with:
|
||||
```bash
|
||||
cd gosuper
|
||||
godep save -r ./...
|
||||
```
|
||||
(The -r switch will modify the import statement to use Godep's `_workspace`)
|
||||
|
@ -1,6 +1,6 @@
|
||||
[program:go-supervisor]
|
||||
directory=/app
|
||||
command=/app/gosuper/bin/gosuper
|
||||
command=/app/bin/gosuper
|
||||
redirect_stderr=true
|
||||
autorestart=true
|
||||
autostart=false
|
||||
|
15
gosuper/Dockerfile
Normal file
15
gosuper/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
FROM golang:1.4.2-cross
|
||||
|
||||
ENV GOOS linux
|
||||
ENV GOPATH /usr/src/app
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY . src/resin-supervisor/gosuper
|
||||
|
||||
RUN chmod +x src/resin-supervisor/gosuper/build_gosuper.sh
|
||||
RUN chmod +x src/resin-supervisor/gosuper/test_formatting.sh
|
||||
|
||||
# Run go install with -a (force rebuilding of all packages)
|
||||
# and -v (print package names as they are built)
|
||||
CMD cd ./src/resin-supervisor/gosuper && ./build_gosuper.sh
|
4
Godeps/Godeps.json → gosuper/Godeps/Godeps.json
generated
4
Godeps/Godeps.json → gosuper/Godeps/Godeps.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"ImportPath": "resin-supervisor",
|
||||
"GoVersion": "go1.4.2",
|
||||
"ImportPath": "resin-supervisor/gosuper",
|
||||
"GoVersion": "go1.3.3",
|
||||
"Packages": [
|
||||
"./..."
|
||||
],
|
0
Godeps/Readme → gosuper/Godeps/Readme
generated
0
Godeps/Readme → gosuper/Godeps/Readme
generated
0
Godeps/_workspace/.gitignore → gosuper/Godeps/_workspace/.gitignore
generated
vendored
0
Godeps/_workspace/.gitignore → gosuper/Godeps/_workspace/.gitignore
generated
vendored
@ -10,7 +10,7 @@ import (
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"resin-supervisor/Godeps/_workspace/src/github.com/gorilla/context"
|
||||
"resin-supervisor/gosuper/Godeps/_workspace/src/github.com/gorilla/context"
|
||||
)
|
||||
|
||||
// NewRouter returns a new router instance.
|
@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"resin-supervisor/Godeps/_workspace/src/github.com/gorilla/context"
|
||||
"resin-supervisor/gosuper/Godeps/_workspace/src/github.com/gorilla/context"
|
||||
)
|
||||
|
||||
type routeTest struct {
|
@ -7,7 +7,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"resin-supervisor/Godeps/_workspace/src/github.com/gorilla/mux"
|
||||
"resin-supervisor/gosuper/Godeps/_workspace/src/github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func pingHandler(w http.ResponseWriter, r *http.Request) {
|
@ -2,30 +2,44 @@ package supertest
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
gosuper "resin-supervisor/gosuper"
|
||||
gosuper "resin-supervisor/gosuper/gosuper"
|
||||
)
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
var supervisorAddress string
|
||||
var config gosuper.UserConfig
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
supervisorIP := os.Getenv("SUPERVISOR_IP")
|
||||
if supervisorIP == "" {
|
||||
t.Fatal("Supervisor IP not set - is it running?")
|
||||
log.Fatal("Supervisor IP not set - is it running?")
|
||||
}
|
||||
|
||||
address := "http://" + supervisorIP + ":48484"
|
||||
supervisorAddress = "http://" + supervisorIP + ":48484"
|
||||
|
||||
request, err := http.NewRequest("GET", address+"/ping?apikey=bananas", nil)
|
||||
gopath := os.Getenv("GOPATH")
|
||||
|
||||
var err error
|
||||
config, err = gosuper.ReadConfig(gopath + "/src/resin-supervisor/gosuper/config.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
request, err := http.NewRequest("GET", supervisorAddress+"/ping?apikey=bananas", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err := http.DefaultClient.Do(request)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -36,42 +50,23 @@ func TestPing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPurge(t *testing.T) {
|
||||
supervisorIP := os.Getenv("SUPERVISOR_IP")
|
||||
if supervisorIP == "" {
|
||||
t.Fatal("Supervisor IP not set - is it running?")
|
||||
}
|
||||
|
||||
address := "http://" + supervisorIP + ":48484"
|
||||
|
||||
gopath := os.Getenv("GOPATH")
|
||||
|
||||
config, err := gosuper.ReadConfig(gopath + "/src/resin-supervisor/config.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
appId := config.ApplicationId
|
||||
|
||||
dataPath := "/resin-data/" + appId
|
||||
err = ioutil.WriteFile(dataPath+"/test", []byte("test"), 777)
|
||||
err := ioutil.WriteFile(dataPath+"/test", []byte("test"), 777)
|
||||
if err != nil {
|
||||
t.Error("Could not create test file for purge")
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("POST", address+"/v1/purge?apikey=bananas", strings.NewReader(`{"appId": "`+appId+`"}`))
|
||||
request, err := http.NewRequest("POST", supervisorAddress+"/v1/purge?apikey=bananas", strings.NewReader(`{"appId": "`+appId+`"}`))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
res, err := client.Do(request)
|
||||
|
||||
res, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
t.Fatalf("Expected 200, got %d", res.StatusCode)
|
||||
}
|
||||
@ -81,7 +76,6 @@ func TestPurge(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !strings.EqualFold(string(contents), `{"Status":"OK","Error":""}`) {
|
||||
t.Errorf("Purge response didn't match the expected JSON, got: %s", contents)
|
||||
}
|
8
gosuper/test_formatting.sh
Normal file
8
gosuper/test_formatting.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -n "$(gofmt -l .)" ]]; then
|
||||
echo "Bad formatting, run make format-gosuper to fix it."
|
||||
exit 1
|
||||
else
|
||||
echo "Formatting test passed."
|
||||
fi
|
@ -76,5 +76,7 @@ module.exports = (secret) ->
|
||||
request.post config.gosuperAddress + '/v1/purge', {json: true, body: applicationId: appId}, ->
|
||||
application.start(app)
|
||||
.pipe(res)
|
||||
.catch (err) ->
|
||||
res.status(503).send(err?.message or err or 'Unknown error')
|
||||
|
||||
return api
|
||||
|
Loading…
x
Reference in New Issue
Block a user