Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Push Images to Dockerhub & Github Packages (#40)
Browse files Browse the repository at this point in the history
* Push to master merges to dockerhub

* Create push_docker.yml

* add github_push target

* Add github registry build and push

* Push to dockerhub from github actions

* add workflows to docker ignore

* templetize

* Apply local boilerplate version

* Test failure

* Reapply boilerplate
  • Loading branch information
EngHabu authored Apr 27, 2020
1 parent 8a3c635 commit 9269bd0
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 11 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/*
bin/*
.github/*
31 changes: 31 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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"
19 changes: 19 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boilerplate/lyft/docker_build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion boilerplate/lyft/docker_build/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
20 changes: 20 additions & 0 deletions boilerplate/lyft/github_workflows/Readme.rst
Original file line number Diff line number Diff line change
@@ -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/<repo>/operator``
2. ``docker.pkg.github.com/lyft/<repo>/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"
31 changes: 31 additions & 0 deletions boilerplate/lyft/github_workflows/master.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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"
19 changes: 19 additions & 0 deletions boilerplate/lyft/github_workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions boilerplate/lyft/github_workflows/update.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions boilerplate/update.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ lyft/golangci_file
lyft/golang_dockerfile
lyft/golang_support_tools
lyft/pull_request_template
lyft/github_workflows

0 comments on commit 9269bd0

Please sign in to comment.