diff --git a/.github/actions/prepare-docker-image/action.yml b/.github/actions/prepare-docker-image/action.yml new file mode 100644 index 00000000..f9a316cf --- /dev/null +++ b/.github/actions/prepare-docker-image/action.yml @@ -0,0 +1,48 @@ +name: Prepare Docker Image +description: Prepare Docker Image for CI +inputs: + docker_image_tag_ci: + description: Docker Image Tag for CI + required: true + +runs: + using: composite + steps: + - uses: actions/checkout@v4 + - name: Prepare for ci + shell: bash + id: prepare-for-ci + run: | + echo "WWWUSER=$(id -u)" >> $GITHUB_ENV + echo "WWWUSER=$(id -u)" >> $GITHUB_OUTPUT + echo "WWWGROUP=$(id -g)" >> $GITHUB_ENV + echo "WWWGROUP=$(id -g)" >> $GITHUB_OUTPUT + - name: Cache Docker Registry + uses: actions/cache@v3 + with: + path: /tmp/docker-registry + key: docker-registry-${{ github.ref }}-${{ github.sha }} + restore-keys: | + docker-registry-${{ github.ref }} + docker-registry- + - name: Boot-up Local Docker Registry + shell: bash + run: docker run -d -p 5000:5000 --restart=always --name registry -v /tmp/docker-registry:/var/lib/registry registry:2 + - name: Wait for Docker Registry + shell: bash + run: npx wait-on tcp:5000 + - name: Get Docker Image Tag + shell: bash + env: + TAG: ${{ inputs.docker_image_tag_ci }} + run: | + echo "DOCKER_IMAGE_TAG_CI=$TAG" >> $GITHUB_ENV + echo TAG $TAG + - name: Docker Compose Pull + shell: bash + run: | + docker pull localhost:5000/jetdisc-ci:${{ inputs.docker_image_tag_ci }} + # - name: List docker images in registry + # shell: bash + # run: | + # curl -X GET http://localhost:5000/v2/_catalog diff --git a/.github/workflows/cd-for-pr.yml b/.github/workflows/cd-for-pr.yml index d1c2ef86..4b049ff7 100644 --- a/.github/workflows/cd-for-pr.yml +++ b/.github/workflows/cd-for-pr.yml @@ -28,3 +28,7 @@ jobs: uses: ./.github/workflows/ci.yml secrets: inherit needs: prepare + image-build-for-ci: + uses: ./.github/workflows/image-build.yml + secrets: inherit + needs: prepare diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml new file mode 100644 index 00000000..8166589e --- /dev/null +++ b/.github/workflows/image-build.yml @@ -0,0 +1,59 @@ +name: Image build +on: + workflow_call: + outputs: + docker_image_tag_ci: + description: Docker image tag for CI + value: ${{ jobs.image-build.outputs.docker_image_tag_ci }} + workflow_dispatch: + +jobs: + image-build: + runs-on: + - ubuntu-latest + outputs: + docker_image_tag_ci: ${{ steps.generate_docker_image_tag.outputs.docker_image_tag_ci }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Cache Docker Build Cache + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: docker-build-cache-${{ github.ref }}-${{ github.sha }} + restore-keys: | + docker-build-cache-${{ github.ref }} + docker-build-cache- + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + - name: Generate Docker Image Tag + id: generate_docker_image_tag + run: | + SHA=${{ github.sha }} + TAG=$(TZ=UTC-9 date '+%Y%m')-${SHA:0:7} + echo "DOCKER_IMAGE_TAG_CI=$TAG" >> $GITHUB_ENV + echo TAG $TAG + echo "docker_image_tag_ci=$TAG" >> $GITHUB_OUTPUT + - name: Cache Docker Registry + uses: actions/cache@v3 + with: + path: /tmp/docker-registry + key: docker-registry-${{ github.ref }}-${{ github.sha }} + restore-keys: | + docker-registry-${{ github.ref }} + docker-registry- + - name: Boot-up Local Docker Registry + run: docker run -d -p 5000:5000 --restart=always --name registry -v /tmp/docker-registry:/var/lib/registry registry:2 + - name: Wait for Docker Registry + run: npx wait-on tcp:5000 + - name: Build Docker Image + run: | + docker buildx bake \ + -f 'infra/docker/image-bake.hcl' \ + --builder="${{ steps.buildx.outputs.name }}" \ + --set='app.tags=localhost:5000/jetdisc-ci:${{ steps.generate_docker_image_tag.outputs.docker_image_tag_ci }}' \ + --set='app.platforms=linux/amd64' \ + --push