diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..e0159d4d --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,64 @@ +name: build image +on: + pull_request: + push: + branches: + - master + tags: + - v* +env: + IMAGE_NAME: paritytech/polkadot-hub-app + +jobs: + build_only: + name: Build Docker image + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: false + build-args: | + VCS_REF="${{ github.sha }}" + BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" + tags: | + ${{ env.IMAGE_NAME }}:${{ github.sha }} + ${{ env.IMAGE_NAME }}:latest + + build_and_push: + name: Build Docker image and push it to Docker Hub + if: ${{ github.ref == 'refs/heads/master' || github.ref_type == 'tag' }} + runs-on: ubuntu-latest + environment: master_and_tags + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Prepare Docker environment + run: | + echo IMAGE_TAG=$(if [ "$GITHUB_REF" == "refs/heads/master" ]; then echo "master-${GITHUB_SHA::7}"; else echo "$GITHUB_REF_NAME"; fi) >> $GITHUB_ENV + echo "Docker image will be published with the tag: ${{ env.IMAGE_TAG }}!" + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_PASS }} + + - name: Build and push Docker image from master + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: ${{ github.ref == 'refs/heads/master' }} + build-args: | + VCS_REF="${{ github.sha }}" + BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" + tags: | + ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + ${{ env.IMAGE_NAME }}:latest diff --git a/Dockerfile b/Dockerfile index 40d478fd..b81a83a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ FROM node:latest -ARG VCS_REF=master -ARG BUILD_DATE="" -ARG REGISTRY_PATH="harbor.parity-mgmt.parity.io/parity-internal" -ARG PROJECT_NAME="" +# metadata +ARG VCS_REF +ARG BUILD_DATE +ARG PROJECT_NAME="polkadot-hub-app" LABEL io.parity.image.authors="cicd-team@parity.io" \ io.parity.image.vendor="Parity Technologies" \ - io.parity.image.title="${REGISTRY_PATH}/${PROJECT_NAME}" \ - io.parity.image.description="${PROJECT_NAME}" \ + io.parity.image.title="${PROJECT_NAME}" \ + io.parity.image.description="Polkadot Hub App is a self-hosted web app for managing offices, meeting rooms, events, and people profiles." \ io.parity.image.source="https://github.com/paritytech/${PROJECT_NAME}/blob/${VCS_REF}/Dockerfile" \ io.parity.image.documentation="https://github.com/paritytech/${PROJECT_NAME}/blob/${VCS_REF}/README.md" \ io.parity.image.revision="${VCS_REF}" \