Skip to content

Commit

Permalink
chore: publish plugin image automatically. move to quay.io
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Suen <[email protected]>
  • Loading branch information
jessesuen committed Apr 22, 2021
1 parent 22c66b2 commit 245f68b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 82 deletions.
152 changes: 75 additions & 77 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,95 @@ 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

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

steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
id: buildx
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Cache Docker layers
uses: actions/cache@v2
with:
install: true
version: latest

- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
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

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- 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
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
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo ::set-output name=tag::$(echo $IMAGE_ID:$VERSION)
- name: Build and push image
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
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: 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}}
-
name: Build and push (controller)
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{steps.generate_tag.outputs.tag}}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.controller-meta.outputs.tags }}
-
name: Build and push (plugin)
uses: docker/build-push-action@v2
with:
target: kubectl-argo-rollouts
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.plugin-meta.outputs.tags }}
-
# 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

0 comments on commit 245f68b

Please sign in to comment.