mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
ci: run versionsapi as docker action
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
7bf7286242
commit
6d6ef99f11
@ -24,9 +24,6 @@ image
|
||||
Dockerfile
|
||||
Dockerfile.*
|
||||
|
||||
# GitHub actions
|
||||
.github
|
||||
|
||||
# VS Code configuration folder
|
||||
.vscode
|
||||
|
||||
|
26
.github/actions/versionsapi/Dockerfile
vendored
Normal file
26
.github/actions/versionsapi/Dockerfile
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
FROM golang:1.19.4@sha256:766625f2182dacec4c8774355a65a81a3b73acb0b4287b6a32a8efc185aede2c as builder
|
||||
|
||||
# Download project root dependencies
|
||||
WORKDIR /workspace
|
||||
# Copy the Go Modules manifests
|
||||
COPY go.mod go.mod
|
||||
COPY go.sum go.sum
|
||||
# cache deps before building and copying source so that we don't need to re-download as much
|
||||
# and so that source changes don't invalidate our downloaded layer
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
# Build
|
||||
WORKDIR /workspace/internal/versionsapi/cli
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o versionsapi .
|
||||
|
||||
FROM alpine:3.17.1@sha256:f271e74b17ced29b915d351685fd4644785c6d1559dd1f2d4189a5e851ef753a as release
|
||||
|
||||
RUN apk add --no-cache bash
|
||||
|
||||
WORKDIR /
|
||||
COPY --from=builder /workspace/internal/versionsapi/cli/versionsapi .
|
||||
COPY .github/actions/versionsapi/entrypoint.sh .
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
49
.github/actions/versionsapi/action.yml
vendored
Normal file
49
.github/actions/versionsapi/action.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
name: versionsapi
|
||||
description: "A GitHub Action to interact with the versions API"
|
||||
|
||||
inputs:
|
||||
command:
|
||||
description: Command to run
|
||||
required: true
|
||||
ref:
|
||||
description: --ref flag
|
||||
required: false
|
||||
stream:
|
||||
description: --stream flag
|
||||
required: false
|
||||
version:
|
||||
description: --version flag
|
||||
required: false
|
||||
add_latest:
|
||||
description: --latest flag (boolean)
|
||||
required: false
|
||||
default: "false"
|
||||
add_release:
|
||||
description: --release flag (boolean)
|
||||
required: false
|
||||
default: "false"
|
||||
rm_all:
|
||||
description: --all flag (boolean)
|
||||
required: false
|
||||
default: "false"
|
||||
dryrun:
|
||||
description: --dryrun flag (boolean)
|
||||
required: false
|
||||
default: "false"
|
||||
outputs:
|
||||
output:
|
||||
description: Output of the command
|
||||
|
||||
runs:
|
||||
using: docker
|
||||
image: docker://ghcr.io/edgelesssys/constellation/versionsapi-ci-cli:latest
|
||||
args:
|
||||
- ${{ inputs.command }}
|
||||
- ${{ inputs.ref != '' && format('--ref={0}', inputs.ref) || '' }}
|
||||
- ${{ inputs.stream != '' && format('--stream={0}', inputs.stream) || '' }}
|
||||
- ${{ inputs.version != '' && format('--version={0}', inputs.version) || '' }}
|
||||
- ${{ inputs.add_latest == 'true' && '--latest' || '' }}
|
||||
- ${{ inputs.add_release == 'true' && '--release' || '' }}
|
||||
- ${{ inputs.rm_all == 'true' && '--all' || '' }}
|
||||
- ${{ inputs.dryrun == 'true' && '--dryrun' || '' }}
|
||||
- --verbose
|
18
.github/actions/versionsapi/entrypoint.sh
vendored
Executable file
18
.github/actions/versionsapi/entrypoint.sh
vendored
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
for arg in "$@"; do
|
||||
if [[ ${arg} != "" ]]; then
|
||||
args[${#args[@]}]="${arg}"
|
||||
fi
|
||||
done
|
||||
|
||||
out=$(/versionsapi "${args[@]}")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${GITHUB_ACTIONS} == "true" ]]; then
|
||||
echo "output=${out}" | tee "${GITHUB_ENV}"
|
||||
else
|
||||
echo "${out}"
|
||||
fi
|
34
.github/workflows/build-versionsapi-ci-image.yml
vendored
Normal file
34
.github/workflows/build-versionsapi-ci-image.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
name: Build and upload versionsapi CI image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "internal/versionsapi/**"
|
||||
|
||||
jobs:
|
||||
build-versionsapi-ci-cli:
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- name: Check out repository
|
||||
id: checkout
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||
with:
|
||||
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
|
||||
|
||||
- name: Setup Go environment
|
||||
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||
with:
|
||||
go-version: "1.19.4"
|
||||
|
||||
- name: Build and upload container image
|
||||
uses: ./.github/actions/build_micro_service
|
||||
with:
|
||||
name: versionsapi-ci-cli
|
||||
dockerfile: .github/actions/versionsapi/Dockerfile
|
||||
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
51
.github/workflows/versionsapi.yml
vendored
51
.github/workflows/versionsapi.yml
vendored
@ -8,9 +8,9 @@ on:
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- add
|
||||
- latest
|
||||
- list
|
||||
- add
|
||||
- remove
|
||||
ref:
|
||||
description: --ref flag
|
||||
@ -97,7 +97,8 @@ jobs:
|
||||
outputs:
|
||||
output: ${{ steps.run.outputs.output }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Check out repository
|
||||
id: checkout
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||
with:
|
||||
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
|
||||
@ -163,41 +164,15 @@ jobs:
|
||||
with:
|
||||
gcp_service_account_json: ${{ secrets.GCP_IMAGE_UPLOAD_SERVICE_ACCOUNT }}
|
||||
|
||||
- name: Setup Go environment
|
||||
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
||||
with:
|
||||
go-version: "1.19.5"
|
||||
cache: true
|
||||
|
||||
- name: Build versionsapi CLI
|
||||
working-directory: internal/versionsapi/cli
|
||||
run: go build -o versionsapi
|
||||
|
||||
- name: Execute versionsapi CLI
|
||||
id: run
|
||||
working-directory: internal/versionsapi/cli
|
||||
run: |
|
||||
set -x
|
||||
|
||||
ref=$([[ -n "${{ inputs.ref }}" ]] && echo "--ref ${{ inputs.ref }}" || echo "")
|
||||
stream=$([[ -n "${{ inputs.stream }}" ]] && echo "--stream ${{ inputs.stream }}" || echo "")
|
||||
version=$([[ -n "${{ inputs.version }}" ]] && echo "--version ${{ inputs.version }}" || echo "")
|
||||
add_latest=$([[ "${{ inputs.add_latest }}" == "true" ]] && echo "--latest" || echo "")
|
||||
add_release=$([[ "${{ inputs.add_release }}" == "true" ]] && echo "--release" || echo "")
|
||||
rm_all=$([[ "${{ inputs.rm_all }}" == "true" ]] && echo "--all" || echo "")
|
||||
dryrun=$([[ "${{ inputs.dryrun }}" == "true" ]] && echo "--dryrun" || echo "")
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
out=$(
|
||||
./versionsapi "${{ inputs.command }}" \
|
||||
${ref} \
|
||||
${stream} \
|
||||
${version} \
|
||||
${add_latest} \
|
||||
${add_release} \
|
||||
${rm_all} \
|
||||
${dryrun} \
|
||||
--verbose
|
||||
)
|
||||
echo "$out"
|
||||
echo "output=$out" >> "$GITHUB_OUTPUT"
|
||||
uses: ./.github/actions/versionsapi
|
||||
with:
|
||||
command: ${{ inputs.command }}
|
||||
ref: ${{ inputs.ref }}
|
||||
stream: ${{ inputs.stream }}
|
||||
version: ${{ inputs.version }}
|
||||
add_latest: ${{ inputs.add_latest }}
|
||||
add_release: ${{ inputs.add_release }}
|
||||
rm_all: ${{ inputs.rm_all }}
|
||||
dryrun: ${{ inputs.dryrun }}
|
||||
|
Loading…
Reference in New Issue
Block a user