From ad136763b0a2a7d2bd45aa9b34329d2e5cf71d9a Mon Sep 17 00:00:00 2001 From: Brandon McClure Date: Mon, 26 Sep 2022 16:48:08 -0600 Subject: [PATCH 1/5] add workflow to build docker --- .github/workflows/build-docker.yml | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/build-docker.yml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 00000000..0b9935ff --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,83 @@ +name: build-docker + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * 0' + push: + branches: + - master # Trigger CI on main branch + pull_request: + branches: + - master # Trigger gated pipeline on PR to main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: brandonmcclure/mineos-node + JUST_IMAGE_NAME: mineos-node + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + tags: | + type=ref,event=pr + type=ref,event=branch + type=sha,format=long + type=raw,value=latest + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + bmcclure89/${{ env.JUST_IMAGE_NAME }} + + - name: Build Docker image (non main branch) + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + if: github.ref != 'refs/heads/main' + with: + context: . + load: true + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: TARGET_ELIXER_TAG=elixir:1.14-alpine + - name: Build and push Docker image (main branch) + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + if: github.ref == 'refs/heads/main' + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: TARGET_ELIXER_TAG=elixir:1.14-alpine + - id: lowercaseImageName + uses: ASzc/change-string-case-action@v2 + with: + string: ${{ env.IMAGE_NAME }} + - name: Save Docker Image archive to local filesystem + run: "docker save --output mineos-node.tar ${{env.REGISTRY}}/${{ steps.lowercaseImageName.outputs.lowercase }}" + - name: Upload application's Docker Image as pipeline artifact + uses: actions/upload-artifact@v2 + with: + path: mineos-node.tar + name: mineos-node.tar From c1746f31a5f04deb5dc3f1fe6254eb106a8ab299 Mon Sep 17 00:00:00 2001 From: Brandon McClure Date: Mon, 26 Sep 2022 17:00:50 -0600 Subject: [PATCH 2/5] use master instead of main --- .github/workflows/build-docker.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 0b9935ff..12013712 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -51,9 +51,9 @@ jobs: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} bmcclure89/${{ env.JUST_IMAGE_NAME }} - - name: Build Docker image (non main branch) + - name: Build Docker image (non master branch) uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - if: github.ref != 'refs/heads/main' + if: github.ref != 'refs/heads/master' with: context: . load: true @@ -61,9 +61,9 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: TARGET_ELIXER_TAG=elixir:1.14-alpine - - name: Build and push Docker image (main branch) + - name: Build and push Docker image (master branch) uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master ' with: context: . push: true From ea1bdd98af70530b15aac9a35277ace4677ccde0 Mon Sep 17 00:00:00 2001 From: Brandon McClure Date: Mon, 26 Sep 2022 17:51:18 -0600 Subject: [PATCH 3/5] no need to save tar --- .github/workflows/build-docker.yml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 12013712..f224e9e9 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -60,7 +60,6 @@ jobs: push: false tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - build-args: TARGET_ELIXER_TAG=elixir:1.14-alpine - name: Build and push Docker image (master branch) uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc if: github.ref == 'refs/heads/master ' @@ -68,16 +67,4 @@ jobs: context: . push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: TARGET_ELIXER_TAG=elixir:1.14-alpine - - id: lowercaseImageName - uses: ASzc/change-string-case-action@v2 - with: - string: ${{ env.IMAGE_NAME }} - - name: Save Docker Image archive to local filesystem - run: "docker save --output mineos-node.tar ${{env.REGISTRY}}/${{ steps.lowercaseImageName.outputs.lowercase }}" - - name: Upload application's Docker Image as pipeline artifact - uses: actions/upload-artifact@v2 - with: - path: mineos-node.tar - name: mineos-node.tar + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From e31ca64fd0e00b7dd0ff0dbb4884dc0254c05533 Mon Sep 17 00:00:00 2001 From: Brandon McClure Date: Mon, 26 Sep 2022 18:02:25 -0600 Subject: [PATCH 4/5] use hexparrot instead of my name --- .github/workflows/build-docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index f224e9e9..10e9d687 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -13,7 +13,7 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: brandonmcclure/mineos-node + IMAGE_NAME: hexparrot/mineos-node JUST_IMAGE_NAME: mineos-node jobs: @@ -49,7 +49,7 @@ jobs: type=raw,value=latest images: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - bmcclure89/${{ env.JUST_IMAGE_NAME }} + hexparrot/${{ env.JUST_IMAGE_NAME }} - name: Build Docker image (non master branch) uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc From 96439de42d4fb405d9c7339dd92abd8f91ed9438 Mon Sep 17 00:00:00 2001 From: Brandon McClure Date: Mon, 26 Sep 2022 18:06:42 -0600 Subject: [PATCH 5/5] re-order to build even without registry creds --- .github/workflows/build-docker.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 10e9d687..58829490 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -27,17 +27,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 @@ -60,6 +50,17 @@ jobs: push: false tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push Docker image (master branch) uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc if: github.ref == 'refs/heads/master '