diff --git a/.github/workflows/pr_master.yml b/.github/workflows/pr_master.yml new file mode 100644 index 00000000..d84e939f --- /dev/null +++ b/.github/workflows/pr_master.yml @@ -0,0 +1,35 @@ + +# build the image on PRs and master + +name: PR + +on: + pull_request: + push: + branches: + - master + paths-ignore: + - 'README.md' + +jobs: + build: + runs-on: ubuntu-latest + env: + COMMIT_HASH: ${{ github.sha }} + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - uses: nelonoel/branch-name@v1.0.1 + + - name: Docker Login + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USER }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" + + - name: Build + env: + BUILD_VERSION: ${{ env.COMMIT_HASH }} + run: make build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..75d8b6a0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +# Build, Tag & Push a new release to dockerhub off of a tag + +name: Release + +on: + push: + tags: + - 'v*' + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - uses: nelonoel/branch-name@v1.0.1 + + - name: Docker Login + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USER }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN" + + - name: Create Version + id: version + run: | + # TODO: find a better way to version from tags + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # set to output var + echo ::set-output name=VERSION::${VERSION} + + - name: Build and Tag + env: + BUILD_VERSION: ${{ steps.version.outputs.VERSION }} + run: make tag-latest + + - name: Push + if: success() + env: + BUILD_VERSION: ${{ steps.version.outputs.VERSION }} + run: make push-latest diff --git a/README.md b/README.md index 24519574..dba3f080 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gRPC/Protocol Buffer Compiler Containers -[![Build Status](https://dev.azure.com/namely/protoc-all/_apis/build/status/namely.docker-protoc?branchName=master)](https://dev.azure.com/namely/protoc-all/_build/latest?definitionId=1&branchName=master) +[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/namely/docker-protoc/Build/master?style=flat-square)](https://github.com/namely/docker-protoc/actions?query=workflow%3ABuild) This repository contains support for various Docker images that wrap `protoc`, `prototool`, `grpc_cli` commands with [gRPC](https://github.com/grpc/grpc) support @@ -35,8 +35,8 @@ If you're having trouble, see [Docker troubleshooting](#docker-troubleshooting) ## Tag Conventions -For `protoc`, `grpc_cli` and `prototool` a pattern of `_` is used for all images. -Example is `namely/protoc-all:1.15_0` for gRPC version `1.15`. The `latest` tag will always point to the most recent version. +For `protoc`, `grpc_cli` and `prototool` a pattern of `_` is used for all images (or `_-rc.`) for pre-releases). +Example is `namely/protoc-all:1.15_0` for gRPC version `1.15` (or `namely/protoc-all:1.15_0-rc.1` for a pre-release). The `latest` tag will always point to the most recent version. ## Usage @@ -243,11 +243,15 @@ Thank you for considering a contribution to namely/docker-protoc! If you'd like to make an enhancement, or add a container for another language compiler, you will need to run one of the build scripts in this repo. You will also need to be running Mac, Linux, -or WSL 2, and have Docker installed. From the repository root, run this command to build all the +or WSL 2, and have Docker installed. + +### Build + +From the repository root, run this command to build all the known containers: ```sh -$ make build +make build ``` Note the version tag in Docker's console output - this image tag is required to run the tests using @@ -258,31 +262,33 @@ make command. For example, this would build the containers using Node.js 15 and interesting variables in [variables.sh](./variables.sh) and [entrypoint.sh](./all/entrypoint.sh). ```sh -$ NODE_VERSION=15 GRPC_VERSION=1.35 make build +NODE_VERSION=15 GRPC_VERSION=1.35 make build ``` +### Test + To run the tests, identify your image tag from the build step and run `make test` as below: ```sh -$ CONTAINER=namely/protoc-all:VVV make test +CONTAINER=namely/protoc-all:VVV make test ``` (`VVV` is your version from the tag in the console output when running `make build`). Running this will demonstrate that your new image can successfully build containers for each language. -Open a PR and ping one of the Namely employees who have worked on this repo recently. We will take -a look as soon as we can. Thank you!! +### Release -Namely employees can merge PRs and the latest version will be pushed up via CI. It is also possible to -do this manually by running this: +#### Contributors -```sh -$ make push -``` +Open a PR and ping one of the Namely employees who have worked on this repo recently. We will take a look as soon as we can. +Thank you!! + +#### Namely Employees -This will build and push the containers to the Namely registry located on -[DockerHub](https://hub.docker.com/u/namely/). You must be authorized to push to -this repo. +Namely employees can merge PRs and cut a release/pre-release by drafting a new Github release and publishing them. +The release name should follow the same tag conventions described in [this doc](#tag-conventions) and the gRPC version in the release name +must match the `GRPC_VERSION` configured in [variables.sh](./variables.sh). +Once a new Github release is published, new images will be published to [DockerHub](https://hub.docker.com/u/namely/) via CI. ## Docker Troubleshooting diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 5adcec9b..00000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,24 +0,0 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- master - -pool: - vmImage: 'ubuntu-latest' - -steps: -- script: make tag-latest - displayName: 'Build and Tag' - -- task: Docker@2 - inputs: - containerRegistry: 'namely-protoc' - command: 'login' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - -- script: make push-latest - displayName: "Docker Push" - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) \ No newline at end of file diff --git a/build.sh b/build.sh index efbe249a..32d01704 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ source ./variables.sh for build in ${BUILDS[@]}; do - tag=${CONTAINER}/${build}:${GRPC_VERSION}_${BUILD_VERSION} + tag=${CONTAINER}/${build}:${BUILD_VERSION} echo "building ${build} container with tag ${tag}" docker build -t ${tag} \ -f Dockerfile \ diff --git a/push.sh b/push.sh index 87c85411..790593b4 100755 --- a/push.sh +++ b/push.sh @@ -3,7 +3,7 @@ source ./variables.sh for build in ${BUILDS[@]}; do - tag=${CONTAINER}/${build}:${GRPC_VERSION}_${BUILD_VERSION} + tag=${CONTAINER}/${build}:${BUILD_VERSION} echo "pushing ${tag}" docker push ${tag} diff --git a/variables.sh b/variables.sh index 7c011842..5ef5f96e 100755 --- a/variables.sh +++ b/variables.sh @@ -3,7 +3,6 @@ BUILDS=("protoc-all" "protoc" "prototool" "grpc-cli" "gen-grpc-gateway") DOCKER_REPO=${DOCKER_REPO} NAMESPACE=${NAMESPACE:-namely} -BUILD_VERSION=${BUILD_VERSION:-1} CONTAINER=${DOCKER_REPO}${NAMESPACE} LATEST=${1:false} @@ -18,3 +17,4 @@ NODE_VERSION=${NODE_VERSION:-14} NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION=${NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION:-5.1.3} NODE_GRPC_TOOLS_VERSION=${NODE_GRPC_TOOLS_VERSION:-1.11.1} NODE_PROTOC_GET_GRPC_WEB_VERSION=${NODE_PROTOC_GET_GRPC_WEB_VERSION:-1.2.1} +BUILD_VERSION="${BUILD_VERSION:-${GRPC_VERSION}_0}"