diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 13bfde0..4e51556 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,3 +13,15 @@ build:signal-server: - docker push ${CI_REGISTRY_IMAGE}/signal-server:${CI_COMMIT_REF_SLUG} - docker push ${CI_REGISTRY_IMAGE}/signal-server:${VERSION} - echo "docker pull ${CI_REGISTRY_IMAGE}/signal-server:${VERSION}" + +build:testhelper: + tags: + - docker-builder + image: docker:latest + stage: build + script: + - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} + - docker build -f testhelper.Dockerfile -t ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_SHA:0:8} . + - docker tag ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_SHA:0:8} ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_REF_SLUG} + - docker push ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_SHA:0:8} + - docker push ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_REF_SLUG} diff --git a/testhelper.Dockerfile b/testhelper.Dockerfile new file mode 100644 index 0000000..1d13b0a --- /dev/null +++ b/testhelper.Dockerfile @@ -0,0 +1,7 @@ +FROM golang:latest +COPY testhelper.go / +RUN go build testhelper.go + +FROM scratch +COPY --from=build /testhelper /testhelper +ENTRYPOINT ["/testhelper"] diff --git a/testhelper.go b/testhelper.go new file mode 100644 index 0000000..8fc16e6 --- /dev/null +++ b/testhelper.go @@ -0,0 +1,31 @@ +package main; + +import ( + "net/http" + // "golang.org/x/net/html" + "database/sql" + _ "github.com/lib/pq" + "os" + "log" + "fmt" +) + +func crash(err error) { + if err != nil { + panic(err) + } +} + +func main() { + db, err := sql.Open("postgres", os.Getenv("DB")) + crash(err) + + http.HandleFunc("/verification-code", func(w http.ResponseWriter, r *http.Request) { + account := r.PostFormValue("account") + var code string + err := db.QueryRow("SELECT verification_code FROM pending_accounts WHERE number = $1", account).Scan(&code) + crash(err) + fmt.Fprintf(w, "%s\n", code) + }) + log.Fatal(http.ListenAndServe(":8082", nil)) +}