Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: add slim version of git plugin #162

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ A Vela plugin designed for cloning repositories into your workspace.

Internally, the plugin is a wrapper around the [git](https://git-scm.com/) CLI.

The plugin comes in two flavors: `vela-git-slim` and `vela-git`

`vela-git-slim` contains basic packages required to perform basic git operations - ideal for regular clone steps.

`vela-git` contains all of `vela-git-slim` and additional utility packages related to git, such as `git-lfs` and `gh` (GitHub CLI).

## Documentation

For installation and usage, please [visit our user docs](https://go-vela.github.io/docs).
Expand Down
80 changes: 45 additions & 35 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,55 @@ name: prerelease
on:
push:
tags:
- 'v*'
- "v*"

# pipeline to execute
jobs:
prerelease:
runs-on: ubuntu-latest

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# ensures we fetch tag history for the repository
fetch-depth: 0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
# use version from go.mod file
go-version-file: 'go.mod'
cache: true
check-latest: true

- name: setup
run: |
# setup git tag in Actions environment
echo "GITHUB_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: build
env:
GOOS: linux
CGO_ENABLED: '0'
run: |
make build-static-ci

- name: publish
uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5
with:
name: target/vela-git
cache: true
tag_names: true
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# ensures we fetch tag history for the repository
fetch-depth: 0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
# use version from go.mod file
go-version-file: "go.mod"
cache: true
check-latest: true

- name: setup
run: |
# setup git tag in Actions environment
echo "GITHUB_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: build
env:
GOOS: linux
CGO_ENABLED: "0"
run: |
make build-static-ci

- name: publish
uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5
with:
name: target/vela-git
cache: true
tag_names: true
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: publish slim
uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5
with:
dockerfile: Dockerfile.slim
name: target/vela-git-slim
cache: true
tag_names: true
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
61 changes: 35 additions & 26 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,48 @@ name: publish
# trigger on push events with branch main
on:
push:
branches: [ main ]
branches: [main]

# pipeline to execute
jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# ensures we fetch tag history for the repository
fetch-depth: 0
- name: clone
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# ensures we fetch tag history for the repository
fetch-depth: 0

- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
# use version from go.mod file
go-version-file: 'go.mod'
cache: true
check-latest: true
- name: install go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
# use version from go.mod file
go-version-file: "go.mod"
cache: true
check-latest: true

- name: build
env:
GOOS: linux
CGO_ENABLED: '0'
run: |
make build-static-ci
- name: build
env:
GOOS: linux
CGO_ENABLED: "0"
run: |
make build-static-ci

- name: publish
uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5
with:
name: target/vela-git
cache: true
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: publish
uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5
with:
name: target/vela-git
cache: true
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: publish slim
uses: elgohr/Publish-Docker-Github-Action@eb53b3ec07136a6ebaed78d8135806da64f7c7e2 # v5
with:
dockerfile: Dockerfile.slim
name: target/vela-git-slim
cache: true
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
23 changes: 14 additions & 9 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ This plugin enables you to clone repositories in a Vela pipeline to your build w

Source Code: https://github.com/go-vela/vela-git

Registry: https://hub.docker.com/r/target/vela-git
Registry:

- https://hub.docker.com/r/target/vela-git-slim
- https://hub.docker.com/r/target/vela-git

## Usage

Expand All @@ -21,7 +24,7 @@ Sample of cloning a repository:
```yaml
steps:
- name: clone_vela-git-test
image: target/vela-git:latest
image: target/vela-git-slim:latest
pull: always
parameters:
path: vela-git-test
Expand All @@ -35,7 +38,7 @@ Sample of cloning a repository with submodules:
```diff
steps:
- name: clone_vela-git-test
image: target/vela-git:latest
image: target/vela-git-slim:latest
pull: always
parameters:
path: vela-git-test
Expand All @@ -50,7 +53,7 @@ Sample of cloning a repository with tags:
```diff
steps:
- name: clone_vela-git-test
image: target/vela-git:latest
image: target/vela-git-slim:latest
pull: always
parameters:
path: vela-git-test
Expand All @@ -60,7 +63,7 @@ steps:
+ tags: true
```

Sample of cloning a repository and resolving LFS objects:
Sample of cloning a repository and resolving LFS objects with the `vela-git` plugin:

```diff
steps:
Expand All @@ -86,7 +89,7 @@ Users can use [Vela internal secrets](https://go-vela.github.io/docs/tour/secret
```diff
steps:
- name: clone_vela-git-test
image: target/vela-git:latest
image: target/vela-git-slim:latest
pull: always
+ secrets: [ git_username, git_password ]
parameters:
Expand Down Expand Up @@ -117,7 +120,7 @@ Users can use [Vela external secrets](https://go-vela.github.io/docs/concepts/pi
```diff
steps:
- name: clone_vela-git-test
image: target/vela-git:latest
image: target/vela-git-slim:latest
pull: always
parameters:
- username: octocat
Expand Down Expand Up @@ -154,7 +157,9 @@ The following parameters are used to configure the image:
| `submodules` | enables fetching of submodules | `false` | `false` | `PARAMETER_SUBMODULES`<br>`GIT_SUBMODULES` |
| `tags` | enables fetching of tags | `false` | `false` | `PARAMETER_TAGS`<br>`GIT_TAGS` |
| `depth` | enables fetching with a specific depth | `false` | `100` | `PARAMETER_DEPTH`<br>`GIT_DEPTH` |
| `lfs` | enables resolving LFS objects | `false` | `false` | `PARAMETER_LFS`<br>`GIT_LFS` |
| `lfs`[^1] | enables resolving LFS objects | `false` | `false` | `PARAMETER_LFS`<br>`GIT_LFS` |

[^1]: only functional in the `target/vela-git` plugin.

## Template

Expand All @@ -167,7 +172,7 @@ You can start troubleshooting this plugin by tuning the level of logs being disp
```diff
steps:
- name: clone_vela-git-test
image: target/vela-git:latest
image: target/vela-git-slim:latest
pull: always
parameters:
+ log_level: trace
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-License-Identifier: Apache-2.0

######################################################################
## docker build --no-cache --target certs -t vela-git:certs . ##
######################################################################

FROM alpine:3.20.2@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5 as certs

RUN apk add --update --no-cache ca-certificates

#######################################################
## docker build --no-cache -t vela-git:local . ##
#######################################################

FROM alpine:3.20.2@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5

COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

RUN apk add --update --no-cache git

COPY release/vela-git /bin/vela-git

ENTRYPOINT [ "/bin/vela-git" ]
Loading