Skip to content

Commit 2bfe89c

Browse files
authored
Switch to GitHub actions (#90)
* Switch to GitHub actions * Use different source of thanos because we can't pull from docker hub due to rate limits... * Move integration test to Docker run only * Switch to new image path under gresearch org * Add an empty circleci config until an admin can delete it
1 parent 9c2c26a commit 2bfe89c

File tree

5 files changed

+119
-159
lines changed

5 files changed

+119
-159
lines changed

.circleci/config.yml

+1-154
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,6 @@
11
version: 2
2-
jobs:
3-
lint:
4-
docker:
5-
- image: circleci/golang
6-
steps:
7-
- checkout
8-
- restore_cache:
9-
keys:
10-
- lint-cache
11-
- run:
12-
name: Check goimports
13-
command: |
14-
files=$(go run golang.org/x/tools/cmd/goimports -l -local "github.com/G-Research" .)
15-
if [[ $files != "" ]]; then
16-
echo "Files need goimports running on them:"
17-
echo "$files"
18-
exit 1
19-
fi
20-
- save_cache:
21-
key: lint-cache
22-
paths:
23-
- "/go/pkg"
242

25-
build:
26-
docker:
27-
- image: circleci/golang:1.12.5
28-
working_directory: /go/src/github.com/G-Research/geras
29-
environment:
30-
GO111MODULE: 'on'
31-
GOBIN: "/go/bin"
32-
SOURCE_IMAGE: g-research/geras
33-
IMAGE_NAME: docker.pkg.github.com/g-research/geras/autobuild
34-
steps:
35-
- checkout
36-
- restore_cache:
37-
keys:
38-
- pkg-cache
39-
- run:
40-
name: Build geras binary
41-
command: go build ./cmd/geras
42-
- run:
43-
name: Run unit tests
44-
command: go test ./...
45-
- run:
46-
name: Check flags are documented
47-
command: test/flags-doc.sh
48-
49-
# Create a docker environment we can use to build docker images
50-
# See https://circleci.com/docs/2.0/building-docker-images/
51-
- setup_remote_docker:
52-
docker_layer_caching: true
53-
54-
- run:
55-
name: Docker build
56-
command: |
57-
set -x
58-
extra=
59-
if [[ "$CIRCLE_TAG" != "" ]]; then
60-
extra="--build-arg GERAS_VERSION=$CIRCLE_TAG"
61-
branch=$CIRCLE_TAG
62-
else
63-
branch=$CIRCLE_BRANCH
64-
fi
65-
docker build -t g-research/geras:$branch --build-arg GIT_REVISION="$CIRCLE_SHA1" --build-arg GIT_BRANCH="$branch" --build-arg BUILD_USER="circleci" $extra .
66-
67-
- run:
68-
name: Docker run without flags
69-
command: |
70-
if [[ -n $CIRCLE_TAG ]]; then
71-
branch=$CIRCLE_TAG
72-
else
73-
branch=$CIRCLE_BRANCH
74-
fi
75-
set +e
76-
docker run -t g-research/geras:$branch
77-
exit=$?
78-
# No flags; so expect help output. Also puts the version output into the CircleCI log
79-
if [[ $exit != 1 ]]; then
80-
echo "Unexpected exit code: $exit"
81-
exit 1
82-
fi
83-
exit 0
84-
85-
- run:
86-
name: Docker compose and test basic query
87-
command: cd test && ./test-query.sh
88-
89-
- run:
90-
name: Push autobuild Docker image
91-
command: |
92-
echo "$GITHUB_DOCKER_TOKEN" | docker login docker.pkg.github.com -u "$GITHUB_DOCKER_USER" --password-stdin
93-
set -x
94-
if [[ $CIRCLE_TAG != "" ]]; then
95-
branch=$CIRCLE_TAG
96-
else
97-
branch=$CIRCLE_BRANCH
98-
fi
99-
if [[ $CIRCLE_TAG == "" ]] && [[ $CIRCLE_BRANCH != "master" ]]; then
100-
echo "Not on a tag or master, skipped."
101-
exit 0
102-
fi
103-
docker tag $SOURCE_IMAGE:$branch $IMAGE_NAME:$branch
104-
docker push $IMAGE_NAME:$branch
105-
106-
- save_cache:
107-
key: pkg-cache
108-
paths:
109-
- "/go/pkg"
110-
111-
docker_release:
112-
docker:
113-
- image: circleci/golang:1.12.5
114-
environment:
115-
SOURCE_IMAGE: docker.pkg.github.com/g-research/geras/autobuild
116-
IMAGE_NAME: docker.pkg.github.com/g-research/geras/geras
117-
steps:
118-
- checkout
119-
- setup_remote_docker
120-
- run:
121-
name: Release tagged commit as release Docker image
122-
command: |
123-
echo "$GITHUB_DOCKER_TOKEN" | docker login docker.pkg.github.com -u "$GITHUB_DOCKER_USER" --password-stdin
124-
set -x
125-
tag=$CIRCLE_TAG
126-
if [[ $tag == "" ]]; then
127-
echo "No tag found"
128-
exit 1
129-
fi
130-
docker pull $SOURCE_IMAGE:$tag
131-
docker pull $IMAGE_NAME:$tag || true
132-
existing=$(docker images -q $IMAGE_NAME:$tag)
133-
if [[ $existing != "" ]]; then
134-
echo "Tag already exists, not overwriting"
135-
exit 1
136-
fi
137-
docker tag $SOURCE_IMAGE:$tag $IMAGE_NAME:$tag
138-
docker push $IMAGE_NAME:$tag
3+
jobs: {}
1394

1405
workflows:
1416
version: 2
142-
143-
build-deploy:
144-
jobs:
145-
- lint
146-
- build:
147-
# Runs on all branches and tags matching /v.*/
148-
filters:
149-
tags:
150-
only: /v.*/
151-
- docker_release:
152-
requires:
153-
- build
154-
# Only run on tags matching /v.*/
155-
filters:
156-
branches:
157-
ignore: /.*/
158-
tags:
159-
only: /v.*/

.github/workflows/docker.yaml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Docker
2+
on:
3+
push:
4+
branches:
5+
- master
6+
# For testing docker building if needed
7+
- build/*
8+
9+
tags:
10+
- v*
11+
12+
env:
13+
IMAGE_NAME: geras
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Log into registry
23+
run: |
24+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
25+
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
26+
27+
- name: Build image
28+
run: |
29+
# Strip git ref prefix from version
30+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
31+
32+
docker build --build-arg GERAS_VERSION=$VERSION --build-arg GIT_REVISION="$GITHUB_SHA" --build-arg GIT_BRANCH="$VERSION" --build-arg BUILD_USER="github-actions" -t image .
33+
34+
- name: Sanity check image
35+
run: |
36+
exit=0
37+
docker run -t image || exit=$?
38+
if [[ $exit != 1 ]]; then
39+
echo "Expected 1 exit (usage), got $exit"
40+
exit 1
41+
fi
42+
43+
# These need docker, so only run as part of the docker build process
44+
- name: Run integration tests
45+
run: |
46+
cd test && ./test-query.sh
47+
48+
- name: Push image
49+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
50+
run: |
51+
GITHUB_ID="docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME"
52+
DOCKERHUB_ID="gresearch/$IMAGE_NAME"
53+
54+
# Change all uppercase to lowercase for github
55+
GITHUB_ID=$(echo $GITHUB_ID | tr '[A-Z]' '[a-z]')
56+
57+
# Strip git ref prefix from version
58+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
59+
60+
# Use Docker `latest` tag convention
61+
[ "$VERSION" == "master" ] && VERSION=latest
62+
echo VERSION=$VERSION
63+
64+
set -x
65+
66+
# GitHub push
67+
docker tag image $GITHUB_ID:$VERSION
68+
docker push $GITHUB_ID:$VERSION
69+
70+
# DockerHub push for releases
71+
if [[ $VERSION != latest ]]; then
72+
docker tag image $DOCKERHUB_ID:$VERSION
73+
docker push $DOCKERHUB_ID:$VERSION
74+
# Also mark release as latest on DockerHub
75+
docker tag image $DOCKERHUB_ID:latest
76+
docker push $DOCKERHUB_ID:latest
77+
fi

.github/workflows/test.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test
2+
on: [push]
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- uses: actions/cache@v1
12+
with:
13+
path: ~/go/pkg/mod
14+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
15+
restore-keys: |
16+
${{ runner.os }}-go-
17+
18+
- name: Check formatting
19+
run: |
20+
files=$(go run golang.org/x/tools/cmd/goimports -l -local "github.com/G-Research" .)
21+
if [[ $files != "" ]]; then
22+
echo "Files need goimports running on them:"
23+
echo "$files"
24+
exit 1
25+
fi
26+
27+
- name: Build binary
28+
run: |
29+
go build ./cmd/...
30+
31+
- name: Check flags are documented
32+
run: |
33+
./test/flags-doc.sh
34+
35+
- name: Run tests
36+
run: |
37+
go test ./...

test/docker-compose.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ faketsdb:
44
- 4242:4242
55

66
geras:
7-
# Uncomment this and comment out image to test locally
7+
# Uncomment and comment out image below to build locally
88
#build: ..
9-
image: g-research/geras:$CIRCLE_BRANCH
9+
# Default to "image" which is what GitHub actions builds
10+
image: image
1011
ports:
1112
- 19000:19000
1213
- 19001:19001
@@ -20,7 +21,7 @@ geras:
2021
- "-http-listen=:19001"
2122

2223
thanos:
23-
image: thanosio/thanos:v0.8.1
24+
image: quay.io/thanos/thanos:v0.18.0
2425
container_name: thanos
2526
ports:
2627
- 10902:10902

test/test-query.sh

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/bash
22
sudo apt-get install -y jq
33

4-
echo "CIRCLE_BRANCH=$CIRCLE_BRANCH" > .env
5-
64
docker-compose up -d --force-recreate
75
if [[ $? != 0 ]]; then
86
docker-compose logs

0 commit comments

Comments
 (0)