From 8975f78333328f5172e62d9fc21d09e74807cf3f Mon Sep 17 00:00:00 2001 From: Arthur Diniz Date: Mon, 14 Jun 2021 19:22:31 -0300 Subject: [PATCH] Improve registry workflow Signed-off-by: Arthur Diniz --- .github/workflows/registry.yml | 106 ++++++++++++++++++++++++++++++--- README.md | 4 ++ 2 files changed, 103 insertions(+), 7 deletions(-) diff --git a/.github/workflows/registry.yml b/.github/workflows/registry.yml index 823b8d6..a0a0732 100644 --- a/.github/workflows/registry.yml +++ b/.github/workflows/registry.yml @@ -1,4 +1,4 @@ -name: Publish Docker image +name: Build and Push Docker image on: push: @@ -6,9 +6,29 @@ on: - '*' jobs: - push_to_ecr: - name: Push Docker image to ECR + build: + name: Build runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build and export + uses: docker/build-push-action@v2 + with: + context: . + tags: dnxsolutions/musketeers:latest + outputs: type=docker,dest=/tmp/musketeers.tar + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: musketeers + path: /tmp/musketeers.tar + ecr: + name: Push to ECR + runs-on: ubuntu-latest + needs: build container: dnxsolutions/aws:2.1.6-dnx1 steps: - name: Check out the repo @@ -22,7 +42,12 @@ jobs: - name: Get the tag id: get_tag run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/} - - name: Build, tag, and push image to Amazon public ECR + - name: Download docker artifact + uses: actions/download-artifact@v2 + with: + name: musketeers + path: /tmp + - name: Load, tag, and push image env: ECR_REGISTRY: public.ecr.aws ECR_REPOSITORY: dnxsolutions/musketeers @@ -30,7 +55,74 @@ jobs: run: | apk add docker aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker load --input /tmp/musketeers.tar + docker image ls -a + docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:latest + docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest + docker tag $ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest - docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest \ No newline at end of file + + docker-hub: + name: Push to Docker Hub + runs-on: ubuntu-latest + needs: build + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DNX_DOCKERHUB_USERNAME }} + password: ${{ secrets.DNX_DOCKERHUB_TOKEN }} + - name: Get the tag + id: get_tag + run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/} + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: musketeers + path: /tmp + - name: Load, tag, and push image + env: + DOCKERHUB_REPOSITORY: dnxsolutions/musketeers + IMAGE_TAG: ${{ steps.get_tag.outputs.tag }} + run: | + docker load --input /tmp/musketeers.tar + docker image ls -a + docker push $DOCKERHUB_REPOSITORY:latest + docker tag $DOCKERHUB_REPOSITORY:latest $DOCKERHUB_REPOSITORY:$IMAGE_TAG + docker push $DOCKERHUB_REPOSITORY:$IMAGE_TAG + + ghcr: + name: Push to GitHub Registry + runs-on: ubuntu-latest + needs: build + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Get the tag + id: get_tag + run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/} + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: musketeers + path: /tmp + - name: Load, tag, and push image + env: + BASE_REPOSITORY: dnxsolutions/musketeers + GHCR_REPOSITORY: ghcr.io/dnxlabs/musketeers + IMAGE_TAG: ${{ steps.get_tag.outputs.tag }} + run: | + docker load --input /tmp/musketeers.tar + docker image ls -a + docker tag $BASE_REPOSITORY:latest $GHCR_REPOSITORY:latest + docker push $GHCR_REPOSITORY:latest + docker tag $GHCR_REPOSITORY:latest $GHCR_REPOSITORY:$IMAGE_TAG + docker push $GHCR_REPOSITORY:$IMAGE_TAG \ No newline at end of file diff --git a/README.md b/README.md index dc4db55..011913d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # docker-musketeers +[![Lint](https://github.com/DNXLabs/docker-musketeers/actions/workflows/lint.yml/badge.svg)](https://github.com/DNXLabs/docker-musketeers/actions/workflows/lint.yml) +[![Security](https://github.com/DNXLabs/docker-musketeers/actions/workflows/security.yml/badge.svg)](https://github.com/DNXLabs/docker-musketeers/actions/workflows/security.yml) +[![Build and Push Docker image](https://github.com/DNXLabs/docker-musketeers/actions/workflows/registry.yml/badge.svg)](https://github.com/DNXLabs/docker-musketeers/actions/workflows/registry.yml) + 🐳 Lightweight image with essential tools for a [3 Musketeers]() project.