From e5f67c93d7dee3561e5924f64bd2c03406372e4b Mon Sep 17 00:00:00 2001 From: rlardy-ulule Date: Mon, 4 Dec 2023 11:18:41 +0100 Subject: [PATCH] feat: added docker build wf --- .github/workflows/linter.yml | 2 +- .github/workflows/mover.yml | 56 ++++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/mover.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 915cb39..0f7c432 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -31,5 +31,5 @@ jobs: version: latest args: -v -c .golangci.yml --timeout 10m # skip-cache: true - # skip-pkg-cache: true + skip-pkg-cache: true # skip-build-cache: true \ No newline at end of file diff --git a/.github/workflows/mover.yml b/.github/workflows/mover.yml new file mode 100644 index 0000000..1c12327 --- /dev/null +++ b/.github/workflows/mover.yml @@ -0,0 +1,56 @@ +name: mover + +on: + push: + branches-ignore: + - 'main' + pull_request: + types: [closed] + branches: + - 'main' + +jobs: + + build: + timeout-minutes: 30 + runs-on: [self-hosted, linux, x64] + + steps: + - name: Checking out repository + uses: actions/checkout@v3 + + - name: Login to GCR + uses: docker/login-action@v2 + with: + registry: ${{ vars.REGISTRY }} + username: _json_key + password: ${{ secrets.GCR_JSON_KEY }} + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ulule + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Removing slashes from branch name when not tag or dev branch + id: git_tag + run: | + if [[ "${{ github.event.pull_request.merged }}" == "true" ]] && [[ "${{ github.ref_name }}" == 'main' ]] && [[ "${{ github.event.pull_request.title }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "GIT_TAG=${{ github.event.pull_request.title }}" >> "$GITHUB_OUTPUT" + else + echo "GIT_TAG=${GIT_REF//\//-}" >> "$GITHUB_OUTPUT" + fi + env: + GIT_REF: ${{ github.ref_name }} + + - name: Build app and push + uses: docker/build-push-action@v4 + with: + file: Dockerfile + push: true + tags: ${{ vars.REGISTRY }}/mover:${{ github.sha }},${{ vars.REGISTRY }}/mover:${{ steps.git_tag.outputs.GIT_TAG }} + cache-from: type=registry,ref=${{ vars.REGISTRY }}/mover:cache + cache-to: type=registry,ref=${{ vars.REGISTRY }}/mover:cache,mode=min,compression=zstd \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0c270a6..bae510c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG CGO_ENABLED=0 WORKDIR /go/src/github.com/ulule/mover -COPY --link . . +COPY . . RUN --mount=type=cache,target=/root/.cache/go-build \ go build -o mover ./cmd/mover/