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

Suffix amazonlinux image with -amazonlinux and push debian image to GitHub #639

Merged
merged 1 commit into from
Dec 8, 2020
Merged
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
118 changes: 72 additions & 46 deletions .github/workflows/container-image.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,79 @@
name: Container Images

on: push
on:
push:

jobs:
build:
buildx:
# this is to prevent the job to run at forked projects
if: github.repository == 'kubernetes-sigs/aws-ebs-csi-driver'
env:
IMAGE: aws-ebs-csi-driver
DEB_BUILD_TAG: aws-ebs-csi-driver:debian
AL2_BUILD_TAG: aws-ebs-csi-driver:amazonlinux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v3
with:
buildx-version: latest
qemu-version: latest
- name: Build container image
run: |
docker buildx build \
-t aws-ebs-csi-driver \
--platform=linux/arm64,linux/amd64 \
--output="type=image,push=false" . \
--target=amazonlinux
- name: Push to Github registry
run: |
USER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
BRANCH=$(echo $GITHUB_REF | cut -d'/' -f3)
IMAGE=aws-ebs-csi-driver
if [ "$BRANCH" = "master" ]; then
TAG="latest"
else
TAG=$BRANCH
fi
docker login docker.pkg.github.com -u $USER -p ${{ secrets.REGISTRY_TOKEN }}
docker build -t aws-ebs-csi-driver . --target amazonlinux
docker tag aws-ebs-csi-driver docker.pkg.github.com/$GITHUB_REPOSITORY/$IMAGE:$TAG
docker push docker.pkg.github.com/$GITHUB_REPOSITORY/$IMAGE:$TAG
- name: Push to Dockerhub registry
run: |
BRANCH=$(echo $GITHUB_REF | cut -d'/' -f3)
REPO=amazon/aws-ebs-csi-driver
if [ "$BRANCH" = "master" ]; then
TAG="latest"
else
TAG=$BRANCH
fi
docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker buildx build \
-t $REPO:$TAG \
--platform=linux/arm64,linux/amd64 \
--output="type=image,push=true" . \
--target=amazonlinux

- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Build debian target
run: |
docker buildx build \
-t $DEB_BUILD_TAG \
--platform=linux/arm64,linux/amd64 \
--output="type=image,push=false" .
--target=debian-base
- name: Build amazonlinux target
run: |
docker buildx build \
-t $AL2_BUILD_TAG \
--platform=linux/arm64,linux/amd64 \
--output="type=image,push=false" . \
--target=amazonlinux
- name: Set environment variables
run: |
BRANCH=$(echo $GITHUB_REF | cut -d'/' -f3)
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
if [ "$BRANCH" = "master" ]; then
TAG="latest"
else
TAG=$BRANCH
fi
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Login to GitHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Push debian target to GitHub
run: |
DEB_PUSH_TAG="docker.pkg.github.com/$GITHUB_REPOSITORY/$IMAGE:$TAG"
docker buildx build \
-t $DEB_PUSH_TAG \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this uses the cache from previous build step ($DEB_BUILD_TAG) . If not, there is no point to $DEB_BUILD_TAG/ $AL2_BUILD_TAG

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm a little bit confused. What's the benefit of build steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes it quicker to debug what failed. if build succeed but push step failed. etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from local testing the build step image is cached so IMO it makes sense to separate the two steps

--platform=linux/arm64,linux/amd64 \
--output="type=image,push=true" . \
--target=debian-base
- name: Push amazonlinux target to GitHub
run: |
AL2_PUSH_TAG="docker.pkg.github.com/$GITHUB_REPOSITORY/$IMAGE:$TAG-amazonlinux"
docker buildx build \
-t $AL2_PUSH_TAG \
--platform=linux/arm64,linux/amd64 \
--output="type=image,push=true" . \
--target=amazonlinux
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push amazonlinux target to Docker Hub
run: |
AL2_PUSH_TAG="amazon/$IMAGE:$TAG-amazonlinux"
docker buildx build \
-t $AL2_PUSH_TAG \
--platform=linux/arm64,linux/amd64 \
--output="type=image,push=true" . \
--target=amazonlinux