From b7c1391e9aa86f1a52cbf1da50ab6b7edfef0aed Mon Sep 17 00:00:00 2001 From: ange Date: Thu, 2 May 2024 17:10:52 +0200 Subject: [PATCH] feat: docker cache --- Dockerfile | 3 +++ action.yaml | 13 ++----------- build.sh | 28 +++++++++++----------------- 3 files changed, 16 insertions(+), 28 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..736d40d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM gcr.io/kaniko-project/executor:debug +COPY build.sh /usr/local/bin/ +ENTRYPOINT ["build.sh"] diff --git a/action.yaml b/action.yaml index 64d2fbf..df8b9e1 100644 --- a/action.yaml +++ b/action.yaml @@ -16,14 +16,5 @@ inputs: required: true runs: - using: composite - steps: - - name: Build - run: ${{ gitea.action_path }}/build.sh - env: - - ACTION_DOCKERFILE=${{ inputs.dockerfile }} - - ACTION_TAG=${{ inputs.tag }} - - ACTION_REGISTRY=${{ gitea.server_url }} - - ACTION_IMAGE=${{ gitea.repository }} - - ACTION_USERNAME=${{ inputs.username }} - - ACTION_PASSWORD=${{ inputs.password }} + using: docker + image: Dockerfile diff --git a/build.sh b/build.sh index 52cc7bc..2db5a17 100755 --- a/build.sh +++ b/build.sh @@ -1,25 +1,19 @@ -#!/bin/bash -e +#!/bin/sh -ex -exec 3<> /tmp/kaniko && rm /tmp/kaniko - -cat <&3 +cat < /kaniko/.docker/config.json { "auths": { - "$ACTION_REGISTRY": { - "username": "$ACTION_USERNAME", - "password": "$ACTION_PASSWORD" + "$GITHUB_SERVER_URL": { + "username": "$INPUT_USERNAME", + "password": "$INPUT_PASSWORD" } } } EOF -REGISTRY="${ACTION_REGISTRY/https:\/\/}" -docker run --rm \ - -v "$PWD:$PWD:ro" \ - -v "$HOME/.cache/kaniko:/cache" \ - -v "/proc/$$/fd/3:/kaniko/.docker/config.json:ro" \ - gcr.io/kaniko-project/executor:latest \ - --cache true \ - --context "${ACTION_DOCKERFILE%/*}" \ - --dockerfile "$ACTION_DOCKERFILE" \ - --destination "$REGISTRY/$ACTION_IMAGE:$ACTION_TAG" +REGISTRY="$(echo "$GITHUB_SERVER_URL" | sed 's .*:// ')" +/kaniko/executor \ + --cache=true \ + --context "${INPUT_DOCKERFILE%/*}" \ + --dockerfile "$INPUT_DOCKERFILE" \ + --destination "$REGISTRY/$GITHUB_REPOSITORY:$INPUT_TAG"