Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard B committed Feb 11, 2021
2 parents 9826541 + 32a3a1e commit d362210
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 42 deletions.
5 changes: 4 additions & 1 deletion env/docker/Dockerfile.buildbase2
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ FROM bbernhard/imagemonkey-buildbase:latest

RUN echo "deb http://deb.debian.org/debian stretch main" >> /etc/apt/sources.list

RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

RUN apt-get update && apt-get install -y --no-install-recommends \
postgresql-client-9.6 \
postgresql-client-13 \
# until this pull request (https://github.com/h2non/bimg/pull/266) is merged and https://github.com/h2non/bimg/issues/269 is resolved, use the fork
&& curl -s https://raw.githubusercontent.com/bbernhard/bimg/master/preinstall.sh | bash - \
&& rm -rf /var/lib/apt/lists/*
64 changes: 36 additions & 28 deletions env/docker/Dockerfile.postgres
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
FROM postgres:9.6.18

ARG TEMPORAL_TABLE_VERSION=1.2.0
ARG POSTGIS_VERSION=2.5
ENV MONKEY_DB_PASSWORD=

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates build-essential postgresql-9.6-postgis-${POSTGIS_VERSION} postgresql-9.6-postgis-${POSTGIS_VERSION}-scripts postgresql-contrib-9.6 postgresql-server-dev-9.6 curl

RUN cd /tmp && curl -o /tmp/v${TEMPORAL_TABLE_VERSION}.tar.gz -L https://github.com/arkhipov/temporal_tables/archive/v${TEMPORAL_TABLE_VERSION}.tar.gz \
&& mkdir -p /tmp/temporal_table \
&& mv /tmp/v${TEMPORAL_TABLE_VERSION}.tar.gz /tmp/temporal_table/v${TEMPORAL_TABLE_VERSION}.tar.gz \
&& cd /tmp/temporal_table && tar xvf v${TEMPORAL_TABLE_VERSION}.tar.gz \
&& cd /tmp/temporal_table/temporal_tables-${TEMPORAL_TABLE_VERSION} \
&& make \
&& make install \
&& rm -rf /tmp_temporal_table

RUN mkdir -p /docker-entrypoint-initdb.d/
COPY env/docker/postgres_init.sh /docker-entrypoint-initdb.d/postgres_init.sh
COPY env/postgres/schema.sql /tmp/imagemonkeydb/schema.sql
COPY env/postgres/defaults.sql /tmp/imagemonkeydb/defaults.sql
COPY env/postgres/indexes.sql /tmp/imagemonkeydb/indexes.sql
COPY env/postgres/stored_procs /tmp/imagemonkeydb/postgres_stored_procs
COPY env/postgres/functions /tmp/imagemonkeydb/postgres_functions

RUN chown -R postgres:postgres /tmp/imagemonkeydb \
&& chmod -R u+rx /tmp/imagemonkeydb
FROM postgres:13

ARG TEMPORAL_TABLE_VERSION=1.2.0
ARG POSTGIS_VERSION=2.5
ENV MONKEY_DB_PASSWORD=

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates build-essential postgresql-13-postgis-${POSTGIS_VERSION} postgresql-13-postgis-${POSTGIS_VERSION}-scripts postgresql-contrib-13 postgresql-server-dev-13 git

#RUN cd /tmp && curl -o /tmp/v${TEMPORAL_TABLE_VERSION}.tar.gz -L https://github.com/arkhipov/temporal_tables/archive/v${TEMPORAL_TABLE_VERSION}.tar.gz \
# && mkdir -p /tmp/temporal_table \
# && mv /tmp/v${TEMPORAL_TABLE_VERSION}.tar.gz /tmp/temporal_table/v${TEMPORAL_TABLE_VERSION}.tar.gz \
# && cd /tmp/temporal_table && tar xvf v${TEMPORAL_TABLE_VERSION}.tar.gz \
# && cd /tmp/temporal_table/temporal_tables-${TEMPORAL_TABLE_VERSION} \
# && make \
# && make install \
# && rm -rf /tmp_temporal_table

RUN cd /tmp && git clone https://github.com/bbernhard/temporal_tables.git \
&& cd /tmp/temporal_tables \
&& git checkout pg13 \
&& make \
&& make install \
&& rm -rf /tmp/temporal_tables


RUN mkdir -p /docker-entrypoint-initdb.d/
COPY env/docker/postgres_init.sh /docker-entrypoint-initdb.d/postgres_init.sh
COPY env/postgres/schema.sql /tmp/imagemonkeydb/schema.sql
COPY env/postgres/defaults.sql /tmp/imagemonkeydb/defaults.sql
COPY env/postgres/indexes.sql /tmp/imagemonkeydb/indexes.sql
COPY env/postgres/stored_procs /tmp/imagemonkeydb/postgres_stored_procs
COPY env/postgres/functions /tmp/imagemonkeydb/postgres_functions

RUN chown -R postgres:postgres /tmp/imagemonkeydb \
&& chmod -R u+rx /tmp/imagemonkeydb
2 changes: 1 addition & 1 deletion env/docker/Dockerfile.testing
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COPY env/postgres /tmp/env/postgres
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ ${DEBIAN_VERSION}-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& apt-get update \
&& apt-get install -y --no-install-recommends python3 postgresql-client-9.6 python3-pip wget unzip \
&& apt-get install -y --no-install-recommends python3 postgresql-client-13 python3-pip wget unzip \
&& pip3 install selenium requests \
&& wget https://chromedriver.storage.googleapis.com/2.44/chromedriver_linux64.zip --directory-prefix=/tmp/ \
&& cd /tmp \
Expand Down
61 changes: 49 additions & 12 deletions src/commons/ci_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"gopkg.in/resty.v1"
"strconv"
"time"
)

type GithubActionsApi struct {
Expand All @@ -23,6 +24,8 @@ type WorkflowRun struct {
HtmlUrl string `json:"html_url"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
HeadBranch string `json:"head_branch"`
Event string `json:"event"`
}

type WorkflowsResult struct {
Expand All @@ -46,13 +49,11 @@ func (p *GithubActionsApi) SetToken(token string) {
p.token = token
}

func (p *GithubActionsApi) GetBuildInfo(branchName string) (CiBuildInfo, error) {
var githubActionsBuildInfo CiBuildInfo
func (p *GithubActionsApi) getBuilds(branchName string) (WorkflowRunsResult, error) {
var res WorkflowRunsResult

url := "https://api.github.com/repos/" + p.repoOwner + "/" + p.repo + "/actions/runs"

var res WorkflowRunsResult

resp, err := resty.R().
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json").
Expand All @@ -63,21 +64,31 @@ func (p *GithubActionsApi) GetBuildInfo(branchName string) (CiBuildInfo, error)
SetResult(&res).
Get(url)
if err != nil {
return githubActionsBuildInfo, err
return res, err
}

if !((resp.StatusCode() >= 200) && (resp.StatusCode() <= 209)) {
return githubActionsBuildInfo, errors.New(resp.String())
return res, errors.New(resp.String())
}
return res,nil
}

if res.TotalCount == 0 {
func (p *GithubActionsApi) GetBuildInfo(branchName string) (CiBuildInfo, error) {
var githubActionsBuildInfo CiBuildInfo

builds, err := p.getBuilds(branchName)
if err != nil {
return githubActionsBuildInfo, err
}

if builds.TotalCount == 0 {
return githubActionsBuildInfo, errors.New("No workflow run found")
}

githubActionsBuildInfo.JobUrl = res.WorkflowRuns[0].HtmlUrl
githubActionsBuildInfo.JobUrl = builds.WorkflowRuns[0].HtmlUrl

status := res.WorkflowRuns[0].Status
conclusion := res.WorkflowRuns[0].Conclusion
status := builds.WorkflowRuns[0].Status
conclusion := builds.WorkflowRuns[0].Conclusion

if status == "queued" {
githubActionsBuildInfo.LastBuild.State = "created"
Expand All @@ -92,7 +103,7 @@ func (p *GithubActionsApi) GetBuildInfo(branchName string) (CiBuildInfo, error)
} else {
githubActionsBuildInfo.LastBuild.State = "failed"
}
githubActionsBuildInfo.LastBuild.Id = res.WorkflowRuns[0].Id
githubActionsBuildInfo.LastBuild.Id = builds.WorkflowRuns[0].Id
return githubActionsBuildInfo, nil
}

Expand Down Expand Up @@ -132,6 +143,13 @@ func (p *GithubActionsApi) StartBuild(branchName string) error {
return err
}

buildsBefore, err := p.getBuilds(branchName)
if err != nil {
return err
}

numBuildsBefore := buildsBefore.TotalCount

var req GithubActionsRequest
req.Ref = branchName

Expand All @@ -152,5 +170,24 @@ func (p *GithubActionsApi) StartBuild(branchName string) error {
return errors.New(resp.String())
}

return nil
//there seems to be no way (yet) to get the build number of the job we manually start.
//so in order to determine the build number, we look at the build that was created at last.
//that's not bulletproof, but it should work well enough.
for i := 0; i < 5; i++ { //it might take a bit until the build number is available
buildsAfter, err := p.getBuilds(branchName)
if err != nil {
time.Sleep(1*time.Second)
continue
}
numBuildsAfter := buildsAfter.TotalCount
if numBuildsAfter == numBuildsBefore + 1 {
if buildsAfter.WorkflowRuns[0].HeadBranch == branchName && buildsAfter.WorkflowRuns[0].Event == "workflow_dispatch" {
return nil
}
}

time.Sleep(1*time.Second)
}

return errors.New("Couldn't get build info after 5 attempts")
}

0 comments on commit d362210

Please sign in to comment.