diff --git a/.dockerignore b/.dockerignore index ce85d3b8c..2117de7bc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ vendor/* bin/* +.github/* diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 000000000..374fe8150 --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,31 @@ +name: Master + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + with: + fetch-depth: '0' + - name: Bump version and push tag + id: bump-version + uses: anothrNick/github-tag-action@1.17.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: patch + - name: Push Docker Image to Github Registry + uses: whoan/docker-build-with-cache-action@v5 + with: + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + image_name: ${{ secrets.flytegithub_repo }}/operator + image_tag: latest,${{ github.sha }},${{ steps.bump-version.outputs.tag }} + push_git_tag: true + registry: docker.pkg.github.com + build_extra_args: "--compress=true" diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 000000000..b87963a5f --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,19 @@ +name: Pull Request + +on: + pull_request + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Push Docker Image to Github Registry + uses: whoan/docker-build-with-cache-action@v5 + with: + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + image_name: ${{ secrets.flytegithub_repo }}/operator + image_tag: ${{ github.sha }} + push_git_tag: true + registry: docker.pkg.github.com diff --git a/.travis.yml b/.travis.yml index c76bde122..2415f1329 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,16 +6,6 @@ services: - docker jobs: include: - - if: fork = true - stage: test - name: docker build - install: true - script: make docker_build - - if: fork = false - stage: test - name: docker build - install: true - script: make docker_build - stage: test install: make install name: lint diff --git a/boilerplate/lyft/docker_build/Makefile b/boilerplate/lyft/docker_build/Makefile index 4019dab83..fa5ef26e8 100644 --- a/boilerplate/lyft/docker_build/Makefile +++ b/boilerplate/lyft/docker_build/Makefile @@ -10,3 +10,7 @@ docker_build: .PHONY: dockerhub_push dockerhub_push: IMAGE_NAME=lyft/$$REPOSITORY REGISTRY=docker.io ./boilerplate/lyft/docker_build/docker_build.sh + +.PHONY: github_push +github_push: + IMAGE_NAME=lyft/$REPOSITORY/$$REPOSITORY REGISTRY=docker.pkg.github.com ./boilerplate/lyft/docker_build/docker_build.sh diff --git a/boilerplate/lyft/docker_build/docker_build.sh b/boilerplate/lyft/docker_build/docker_build.sh index f504c100c..a32a4b86c 100755 --- a/boilerplate/lyft/docker_build/docker_build.sh +++ b/boilerplate/lyft/docker_build/docker_build.sh @@ -47,7 +47,7 @@ echo "${IMAGE_TAG_WITH_SHA} built locally." if [ -n "$REGISTRY" ]; then if [ -n "${DOCKER_REGISTRY_PASSWORD}" ]; then - docker login --username="$DOCKER_REGISTRY_USERNAME" --password="$DOCKER_REGISTRY_PASSWORD" + docker login ${REGISTRY} --username="$DOCKER_REGISTRY_USERNAME" --password="$DOCKER_REGISTRY_PASSWORD" fi docker tag "$IMAGE_TAG_WITH_SHA" "${REGISTRY}/${IMAGE_TAG_WITH_SHA}" diff --git a/boilerplate/lyft/github_workflows/Readme.rst b/boilerplate/lyft/github_workflows/Readme.rst new file mode 100644 index 000000000..d32ba7cb4 --- /dev/null +++ b/boilerplate/lyft/github_workflows/Readme.rst @@ -0,0 +1,20 @@ +Golang Github Actions +~~~~~~~~~~~~~~~~~ + +Provides a two github actions workflows. + +**To Enable:** + +Add ``lyft/github_workflows`` to your ``boilerplate/update.cfg`` file. + +Add a github secret ``flytegithub_repo`` with a the name of your fork (e.g. ``my_company/flytepropeller``). + +The actions will push to 2 repos: + + 1. ``docker.pkg.github.com/lyft//operator`` + 2. ``docker.pkg.github.com/lyft//operator-stages`` : this repo is used to cache build stages to speed up iterative builds after. + +There are two workflows that get deployed: + + 1. A workflow that runs on Pull Requests to build and push images to github registy tagged with the commit sha. + 2. A workflow that runs on master merges that bump the patch version of release tag, builds and pushes images to github registry tagged with the version, commit sha as well as "latest" diff --git a/boilerplate/lyft/github_workflows/master.yml b/boilerplate/lyft/github_workflows/master.yml new file mode 100644 index 000000000..374fe8150 --- /dev/null +++ b/boilerplate/lyft/github_workflows/master.yml @@ -0,0 +1,31 @@ +name: Master + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + with: + fetch-depth: '0' + - name: Bump version and push tag + id: bump-version + uses: anothrNick/github-tag-action@1.17.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + DEFAULT_BUMP: patch + - name: Push Docker Image to Github Registry + uses: whoan/docker-build-with-cache-action@v5 + with: + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + image_name: ${{ secrets.flytegithub_repo }}/operator + image_tag: latest,${{ github.sha }},${{ steps.bump-version.outputs.tag }} + push_git_tag: true + registry: docker.pkg.github.com + build_extra_args: "--compress=true" diff --git a/boilerplate/lyft/github_workflows/pull_request.yml b/boilerplate/lyft/github_workflows/pull_request.yml new file mode 100644 index 000000000..b87963a5f --- /dev/null +++ b/boilerplate/lyft/github_workflows/pull_request.yml @@ -0,0 +1,19 @@ +name: Pull Request + +on: + pull_request + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Push Docker Image to Github Registry + uses: whoan/docker-build-with-cache-action@v5 + with: + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + image_name: ${{ secrets.flytegithub_repo }}/operator + image_tag: ${{ github.sha }} + push_git_tag: true + registry: docker.pkg.github.com diff --git a/boilerplate/lyft/github_workflows/update.sh b/boilerplate/lyft/github_workflows/update.sh new file mode 100755 index 000000000..1e3a09918 --- /dev/null +++ b/boilerplate/lyft/github_workflows/update.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. +# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY: +# +# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst + +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" + +mkdir -p ${DIR}/../../../.github/workflows + +echo " - generating github action workflows in root directory." +sed -e "s/{{REPOSITORY}}/${REPOSITORY}/g" ${DIR}/master.yml > ${DIR}/../../../.github/workflows/master.yml +sed -e "s/{{REPOSITORY}}/${REPOSITORY}/g" ${DIR}/pull_request.yml > ${DIR}/../../../.github/workflows/pull_request.yml diff --git a/boilerplate/update.cfg b/boilerplate/update.cfg index 2d383eeda..b61b59668 100644 --- a/boilerplate/update.cfg +++ b/boilerplate/update.cfg @@ -4,3 +4,4 @@ lyft/golangci_file lyft/golang_dockerfile lyft/golang_support_tools lyft/pull_request_template +lyft/github_workflows