Skip to content

Commit

Permalink
Merge pull request itpp-labs#10 from yelizariev/concourse-ci
Browse files Browse the repository at this point in the history
Concourse CI
  • Loading branch information
Ivan Yelizariev committed Nov 23, 2019
2 parents 9402fb1 + 77ffdb0 commit 4732c00
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY default-config.json /data/config.json
RUN go install github.com/it-projects-llc/hound/cmds/houndd

RUN [ "$DEV" = "yes" ] \
&& apk add npm || true
&& apk add npm make || true

RUN [ "$DEV" = "no" ] \
&& apk del go \
Expand Down
6 changes: 3 additions & 3 deletions DockerfilePR
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# it's used in .github/workflow/pr.yml
FROM docker.pkg.github.com/it-projects-llc/hound/ci
# it's used in concourse.yml
FROM docker.pkg.github.com/it-projects-llc/hound/dev

COPY . /go/src/github.com/it-projects-llc/hound

RUN go install github.com/it-projects-llc/hound/cmds/houndd
RUN make -C /go/src/github.com/it-projects-llc/hound
73 changes: 73 additions & 0 deletions concourse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Concourse CI

* Overview and Docs: https://concourse-ci.org/
* Tutorial: https://concoursetutorial.com/

# Deployment

### Concourse CI

First, download compose file:

wget https://concourse-ci.org/docker-compose.yml

Now edit that file to set password and url:

CONCOURSE_EXTERNAL_URL: http://ci.example.com:8080
CONCOURSE_ADD_LOCAL_USER: ADMIN_LOGIN:ADMIN_PASSWORD
CONCOURSE_MAIN_TEAM_LOCAL_USER: ADMIN_LOGIN

Start:

docker-compose up -d

Now open the url and find link to download *CLI tools*.

Install fly CLI:

sudo mkdir -p /usr/local/bin
sudo mv ~/Downloads/fly /usr/local/bin
sudo chmod 0755 /usr/local/bin/fly


Finally, create *Target*:

fly --target hound login --concourse-url http://ci.example.com:8080 -u ADMIN_LOGIN -p ADMIN_PASSWORD

### Github Token

Create a token with the following access rights:

* ``write:packages``
* ``repo:status``

### Parameters file

Create a file ``concourse-params.yml`` of the the following content:

github-username: USERNAME
github-token: TOKEN
webhook-token: ANY-RANDOM-STRING

* Use TOKEN that created for USERNAME

### Set Pipeline

Execute following command:

fly --target=hound set-pipeline --pipeline=pull-requests --config=concourse.yml --load-vars-from=concourse-params.yml

### Github Webhook

At Github Repository configure webhook to [Concourse CI API](https://concourse-ci.org/resources.html#resource-webhook-token):

* **Payload URL**: *http://CI.EXAMPLE.COM:8080/api/v1/teams/main/pipelines/pull-requests/resources/pr/check/webhook?webhook_token=WEBHOOK_TOKEN*
* **Content Type**: any value is ok
* **Secret**: leave empty
* **Which events would you like to trigger this webhook?**: *Let me select individual events.*:

* **[v] Pull Requests**




93 changes: 93 additions & 0 deletions concourse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# see concourse.md for deployment instructions
resource_types:
- name: pull-request
type: docker-image
source:
repository: teliaoss/github-pr-resource

resources:
- name: pr
type: pull-request
#check_every: 24h
webhook_token: ((webhook-token))
source:
repository: it-projects-llc/hound
access_token: ((github-token))

- name: docker-registry
type: docker-image
source:
repository: docker.pkg.github.com/it-projects-llc/hound/dev
username: ((github-username))
password: ((github-token))

jobs:
- name: build_image
plan:
- get: pr
trigger: true
version: latest
- put: set-status-pending
resource: pr
params:
path: pr
status: pending

- task: analyze-pr
config:
platform: linux
image_resource:
type: docker-image
source: {repository: alpine, tag: "latest"}
inputs:
- name: pr
outputs:
- name: pr-info
run:
path: /bin/sh
args:
- -xce
- |
BASE_SHA=$(cat pr/.git/resource/base_sha)
HEAD_SHA=$(cat pr/.git/resource/head_sha)
PR_NUM=$(cat pr/.git/resource/pr)
TAG="pr-$PR-head-$HEAD_SHA-base-$BASE"
echo $TAG > pr-info/tag.txt
echo "To test updates run:
docker run -p 6080:6080 --rm docker.pkg.github.com/it-projects-llc/hound/dev:$TAG
You may need be [authenticated](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line):
docker login docker.pkg.github.com -u GITHUB_USERNAME -p GITHUB_TOKEN
> Posted from Concourse CI (see concourse.yml)" > pr-info/comment.txt
on_failure:
put: set-status-failure
resource: pr
params:
path: pr
status: failure

- put: docker-registry
params:
build: pr
dockerfile: pr/DockerfilePR
tag_file: pr-info/tag.txt

on_failure:
put: set-status-failure
resource: pr
params:
path: pr
status: failure

- put: set-status-success
resource: pr
params:
path: pr
status: success
target_url: $ATC_EXTERNAL_URL/builds/$BUILD_ID
# it's not neccesary to post comment if we print it as a log in the pipeline
comment_file: pr-info/comment.txt

0 comments on commit 4732c00

Please sign in to comment.