From 118ce438c871c555596ea2b651a1115cc85ac3d0 Mon Sep 17 00:00:00 2001 From: Prashant Srivastava <50466688+srprash@users.noreply.github.com> Date: Fri, 16 Apr 2021 14:27:28 -0700 Subject: [PATCH] Workflow - Publish DockerHub image built on amazonlinux (#132) * Adding separate workflow for dockerhub * adding build step * Splitting ECR and DockerHub images step * Updating continuous build wf as well --- .github/workflows/continuous-build.yml | 17 ++++- .github/workflows/release-build-publish.yml | 24 +++++-- .../workflows/release-publish-Dockerhub.yml | 66 +++++++++++++++++++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release-publish-Dockerhub.yml diff --git a/.github/workflows/continuous-build.yml b/.github/workflows/continuous-build.yml index 6c30bc0..78b117f 100644 --- a/.github/workflows/continuous-build.yml +++ b/.github/workflows/continuous-build.yml @@ -123,15 +123,28 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- - - name: Build docker image + - name: Build docker image for public ECR if: ${{ runner.os == 'Linux' }} uses: docker/build-push-action@v2 with: context: . + file: ./Dockerfile push: ${{ github.event_name == 'push' }} platforms: linux/amd64,linux/arm64 tags: | - amazon/aws-xray-daemon:alpha public.ecr.aws/xray/aws-xray-daemon:alpha cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Build docker image for DockerHub + if: ${{ runner.os == 'Linux' }} + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.amazonlinux + push: ${{ github.event_name == 'push' }} + platforms: linux/amd64,linux/arm64 + tags: | + amazon/aws-xray-daemon:alpha + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache \ No newline at end of file diff --git a/.github/workflows/release-build-publish.yml b/.github/workflows/release-build-publish.yml index 83be000..46f76e1 100644 --- a/.github/workflows/release-build-publish.yml +++ b/.github/workflows/release-build-publish.yml @@ -5,6 +5,9 @@ on: version: description: The version to tag the release with, e.g., 1.2.0, 1.2.1-alpha.1 required: true + major_version: + description: The major version to tag the release with, e.g., 1.x, 2.x, 3.x + required: true jobs: build_publish_daemon_image: @@ -93,17 +96,30 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- - - name: Build docker image + - name: Build docker image for Public ECR uses: docker/build-push-action@v2 with: context: . + file: ./Dockerfile platforms: linux/amd64,linux/arm64 tags: | - amazon/aws-xray-daemon:${{ github.event.inputs.version }} - amazon/aws-xray-daemon:latest - amazon/aws-xray-daemon:3.x public.ecr.aws/xray/aws-xray-daemon:${{ github.event.inputs.version }} public.ecr.aws/xray/aws-xray-daemon:latest + public.ecr.aws/xray/aws-xray-daemon:${{ github.event.inputs.major_version }} + push: true + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Build docker image for DockerHub + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.amazonlinux + platforms: linux/amd64,linux/arm64 + tags: | + amazon/aws-xray-daemon:${{ github.event.inputs.version }} + amazon/aws-xray-daemon:latest + amazon/aws-xray-daemon:${{ github.event.inputs.major_version }} push: true cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/.github/workflows/release-publish-Dockerhub.yml b/.github/workflows/release-publish-Dockerhub.yml new file mode 100644 index 0000000..8d1a91f --- /dev/null +++ b/.github/workflows/release-publish-Dockerhub.yml @@ -0,0 +1,66 @@ +name: Build and release DockerHub image +on: + workflow_dispatch: + inputs: + version: + description: The complete version to tag the release with, e.g., 1.2.0, 1.2.1-alpha.1 + required: true + major_version: + description: The major version to tag the release with, e.g., 2.x, 3.x + required: true + +jobs: + build_publish_DockerHub_image: + name: Build X-Ray daemon docker image with amazonlinux base & release to DockerHub + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '^1.16' + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Build and test + run: make build test + env: + VERSION: ${{ github.event.inputs.version }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-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: Build docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile.amazonlinux + platforms: linux/amd64,linux/arm64 + tags: | + amazon/aws-xray-daemon:${{ github.event.inputs.version }} + amazon/aws-xray-daemon:latest + amazon/aws-xray-daemon:${{ github.event.inputs.major_version }} + push: true + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache