Skip to content

Commit

Permalink
Merge pull request #34 from aertje/cicd
Browse files Browse the repository at this point in the history
Make docker image publish dependent on tests, and only publish if mas…
  • Loading branch information
aertje authored Apr 19, 2021
2 parents 6136ac8 + 4dfd49e commit d1a88b2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 62 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/go-test.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,64 @@
name: Publish Docker image

name: CI/CD
on:
push:
pull_request:

env:
IMAGE_NAME: cloud-tasks-emulator

jobs:
Build-and-Push-Docker-Image:
test:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: go build -v .
- name: Test
run: go test -v .
docker-smoke-test:
runs-on: ubuntu-latest
name: Docker Build, Tag, Push
steps:
- name: Checkout
uses: actions/checkout@v1

uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Cache smoketest dependencies
uses: actions/cache@v2
with:
path: /tmp/smoketest-packages
key: smoketests-pkgs-${{ hashFiles('docker-smoketests/go.*') }}
restore-keys: |
smoketests-pkgs
- name: Run container smoketests
run: EMULATOR_DOCKER_IMAGE=$IMAGE_NAME docker-smoketests/smoketests.sh

# Only attempt to publish the image if this is triggered by a `push` (e.g. direct to the repo by a collaborator,
# not an external pull request). This step would anyway fail on a pull_request workflow because the required
# secret would not be available.
- name: Publish to GitHub Container Registry
if: ${{ github.event_name == 'push' }}
docker-publish:
runs-on: ubuntu-latest
needs: [test, docker-smoke-test]
if: ${{ github.event_name == 'push' && startsWith('refs/tags/v', github.ref) }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Publish to Github Packages
run: |
set -o errexit
set -o nounset
Expand All @@ -54,6 +79,9 @@ jobs:
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Push to the remote repo
# This assumes a higher version will always be tagged later
echo "Publishing $IMAGE_ID:$VERSION"
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
6 changes: 3 additions & 3 deletions readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ docker run -p 8123:8123 tasks_emulator -host 0.0.0.0 -port 8123 -queue projects/
```

### Docker image
Or even easier (thanks @acoulton!) - pull and run it directly from GitHub Container Registry:
Or even easier - pull and run it directly from GitHub Container Registry:
```
docker run ghcr.io/aertje/cloud-tasks-emulator:master
docker run ghcr.io/aertje/cloud-tasks-emulator:latest
```

### Docker Compose
If you are planning on using docker-compose the above configuration translates to :
```
gcloud-tasks-emulator:
image: ghcr.io/aertje/cloud-tasks-emulator:master
image: ghcr.io/aertje/cloud-tasks-emulator:latest
command: -host 0.0.0.0 -port 8123 -queue "projects/dev/locations/here/queues/anotherq"
ports:
- "${TASKS_PORT:-8123}:8123"
Expand Down

0 comments on commit d1a88b2

Please sign in to comment.