Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: publish plugin image automatically. move to quay.io #1102

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 81 additions & 70 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,108 @@ name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
- release-*
tags:
- v*
- v*.*.*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: argo-rollouts

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
docker:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi

# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
- name: Checkout
uses: actions/checkout@v2

runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true
version: latest

- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Login to Quay.io
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}

- name: Log into GitHub Container Registry
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Generate tag
id: generate_tag
- name: Docker meta (controller)
id: controller-meta
uses: crazy-max/ghaction-docker-meta@v2
with:
images: |
quay.io/argoproj/argo-rollouts
ghcr.io/argoproj/argo-rollouts
tags: |
type=ref,event=branch
type=semver,pattern={{version}}

- name: Docker meta (plugin)
id: plugin-meta
uses: crazy-max/ghaction-docker-meta@v2
with:
images: |
quay.io/argoproj/kubectl-argo-rollouts
ghcr.io/argoproj/kubectl-argo-rollouts
tags: |
type=ref,event=branch
type=semver,pattern={{version}}

# avoid building linux/arm64 for PRs since it takes so long
- name: Set Platform Matrix
id: platform-matrix
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')

# 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//')

# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
PLATFORM_MATRIX=linux/amd64
if [ ${{ github.event_name != 'pull_request' }} = true ]; then
PLATFORM_MATRIX=$PLATFORM_MATRIX,linux/arm64
fi
echo "::set-output name=platform-matrix::$PLATFORM_MATRIX"

echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
- name: Build and push (controller)
uses: docker/build-push-action@v2
with:
platforms: ${{ steps.platform-matrix.outputs.platform-matrix }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.controller-meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

echo ::set-output name=tag::$(echo $IMAGE_ID:$VERSION)
- name: Build and push image
- name: Build and push (plugin)
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{steps.generate_tag.outputs.tag}}
target: kubectl-argo-rollouts
platforms: ${{ steps.platform-matrix.outputs.platform-matrix }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.plugin-meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ endif

ifeq (${DOCKER_PUSH},true)
ifndef IMAGE_NAMESPACE
$(error IMAGE_NAMESPACE must be set to push images (e.g. IMAGE_NAMESPACE=argoproj))
$(error IMAGE_NAMESPACE must be set to push images (e.g. IMAGE_NAMESPACE=quay.io/argoproj))
endif
endif

Expand Down
2 changes: 1 addition & 1 deletion manifests/base/argo-rollouts-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
serviceAccountName: argo-rollouts
containers:
- name: argo-rollouts
image: argoproj/argo-rollouts:latest
image: quay.io/argoproj/argo-rollouts:latest
imagePullPolicy: Always
ports:
- containerPort: 8090
Expand Down
2 changes: 1 addition & 1 deletion manifests/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ resources:
- argo-rollouts-aggregate-roles.yaml
- argo-rollouts-metrics-service.yaml
images:
- name: argoproj/argo-rollouts
- name: quay.io/argoproj/argo-rollouts
newTag: latest
2 changes: 1 addition & 1 deletion manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12811,7 +12811,7 @@ spec:
app.kubernetes.io/name: argo-rollouts
spec:
containers:
- image: argoproj/argo-rollouts:latest
- image: quay.io/argoproj/argo-rollouts:latest
imagePullPolicy: Always
name: argo-rollouts
ports:
Expand Down
2 changes: 1 addition & 1 deletion manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12812,7 +12812,7 @@ spec:
containers:
- args:
- --namespaced
image: argoproj/argo-rollouts:latest
image: quay.io/argoproj/argo-rollouts:latest
imagePullPolicy: Always
name: argo-rollouts
ports:
Expand Down