diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml deleted file mode 100644 index 4d0d06d..0000000 --- a/.github/workflows/go-test.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Go Test - -on: - push: - pull_request: - -jobs: - - build: - name: Build - 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 . diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/workflow.yml similarity index 53% rename from .github/workflows/publish-docker.yml rename to .github/workflows/workflow.yml index 2c680e0..a49d06c 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/workflow.yml @@ -1,23 +1,45 @@ -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: @@ -25,15 +47,18 @@ jobs: 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 @@ -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 diff --git a/readme.MD b/readme.MD index a2cd936..ff29849 100644 --- a/readme.MD +++ b/readme.MD @@ -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"