|
| 1 | +name: "CLI: publish image" |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [main] |
| 5 | + |
| 6 | +env: |
| 7 | + REGISTRY: ghcr.io |
| 8 | + IMAGE_NAME: utbot_java_cli |
| 9 | + DOCKERFILE_PATH: docker/Dockerfile_java_cli |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-publish-docker: |
| 13 | + runs-on: ubuntu-20.04 |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Set timezone |
| 19 | + |
| 20 | + with: |
| 21 | + timezoneLinux: "Europe/Moscow" |
| 22 | + |
| 23 | + - name: Set environment variables |
| 24 | + run: |
| 25 | + echo "COMMIT_SHORT_SHA="$(git rev-parse --short HEAD)"" >> $GITHUB_ENV |
| 26 | + |
| 27 | + - name: Set docker tag |
| 28 | + run: |
| 29 | + echo "DOCKER_TAG="$(date +%Y).$(date +%-m).$(date +%-d)-${{ env.COMMIT_SHORT_SHA }}"" >> $GITHUB_ENV |
| 30 | + |
| 31 | + - name: Log in to the Container registry |
| 32 | + uses: docker/login-action@v1 |
| 33 | + with: |
| 34 | + registry: ${{ env.REGISTRY }} |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Set up Docker Buildx |
| 39 | + uses: docker/setup-buildx-action@v1 |
| 40 | + |
| 41 | + - name: Cache Docker layers |
| 42 | + uses: actions/cache@v2 |
| 43 | + with: |
| 44 | + path: /tmp/.buildx-cache |
| 45 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 46 | + restore-keys: | |
| 47 | + ${{ runner.os }}-buildx- |
| 48 | + |
| 49 | + - name: Docker meta |
| 50 | + id: meta |
| 51 | + uses: docker/metadata-action@v3 |
| 52 | + with: |
| 53 | + images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }} |
| 54 | + tags: | |
| 55 | + type=raw,value=${{ env.DOCKER_TAG }} |
| 56 | + |
| 57 | + - name: Docker Buildx (build and push) |
| 58 | + run: | |
| 59 | + docker buildx build \ |
| 60 | + -f ${{ env.DOCKERFILE_PATH }} \ |
| 61 | + --cache-from "type=local,src=/tmp/.buildx-cache" \ |
| 62 | + --cache-to "type=local,dest=/tmp/.buildx-cache-new" \ |
| 63 | + --tag ${{ steps.meta.outputs.tags }} \ |
| 64 | + --build-arg ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }} \ |
| 65 | + --push . |
| 66 | +
|
| 67 | + # Temp fix |
| 68 | + # https://github.com/docker/build-push-action/issues/252 |
| 69 | + # https://github.com/moby/buildkit/issues/1896 |
| 70 | + - name: Move cache |
| 71 | + run: | |
| 72 | + rm -rf /tmp/.buildx-cache |
| 73 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments