2024-10-18 12:26:36 +00:00
|
|
|
apiVersion: argoproj.io/v1alpha1
|
|
|
|
kind: Workflow
|
|
|
|
metadata:
|
|
|
|
generateName: example-ci-workflow-
|
|
|
|
namespace: argo
|
|
|
|
labels:
|
|
|
|
workflows.argoproj.io/archive-strategy: "false"
|
|
|
|
annotations:
|
|
|
|
workflows.argoproj.io/description: |
|
|
|
|
This is a simple workflow to show what steps we need to take to deploy an application.
|
|
|
|
spec:
|
|
|
|
entrypoint: ci
|
|
|
|
serviceAccountName: admin
|
2024-10-22 14:06:32 +00:00
|
|
|
volumeClaimTemplates:
|
2024-10-24 11:35:21 +00:00
|
|
|
- metadata:
|
|
|
|
name: shared-data
|
|
|
|
spec:
|
|
|
|
accessModes: ["ReadWriteOnce"]
|
|
|
|
resources:
|
|
|
|
requests:
|
|
|
|
storage: 1Gi
|
2024-10-23 13:14:37 +00:00
|
|
|
volumes:
|
2024-10-24 11:35:21 +00:00
|
|
|
- name: docker-config
|
|
|
|
secret:
|
|
|
|
secretName: my-docker-secret
|
2024-10-18 12:26:36 +00:00
|
|
|
templates:
|
2024-10-24 11:35:21 +00:00
|
|
|
- name: ci
|
|
|
|
dag:
|
|
|
|
tasks:
|
|
|
|
- name: git-clone
|
|
|
|
template: git-clone
|
|
|
|
arguments:
|
|
|
|
parameters: [{ name: message, value: "git-clone task completed" }]
|
|
|
|
- name: ls
|
|
|
|
template: ls
|
|
|
|
dependencies: [git-clone]
|
|
|
|
- name: build
|
|
|
|
template: build
|
|
|
|
arguments:
|
|
|
|
parameters: [{ name: message, value: "build task completed" }]
|
|
|
|
dependencies: [unit-tests, lint-scan]
|
|
|
|
- name: unit-tests
|
|
|
|
template: unit-tests
|
|
|
|
arguments:
|
|
|
|
parameters:
|
|
|
|
[{ name: message, value: "unit-tests task completed" }]
|
|
|
|
dependencies: [ls]
|
|
|
|
- name: lint-scan
|
|
|
|
template: lint-scan
|
|
|
|
arguments:
|
|
|
|
parameters: [{ name: message, value: "lint-scan task completed" }]
|
|
|
|
dependencies: [ls]
|
|
|
|
- name: trivy-image-scan
|
|
|
|
template: simple-container
|
|
|
|
arguments:
|
|
|
|
parameters:
|
|
|
|
[{ name: message, value: "trivy-image-scan task completed" }]
|
|
|
|
dependencies: [build]
|
|
|
|
- name: trivy-filesystem-scan
|
|
|
|
template: simple-container
|
|
|
|
arguments:
|
|
|
|
parameters:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: message,
|
|
|
|
value: "trivy-filesystem-scan task completed",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
dependencies: [git-clone]
|
|
|
|
- name: push-image
|
|
|
|
template: simple-container
|
|
|
|
arguments:
|
|
|
|
parameters:
|
|
|
|
[{ name: message, value: "push-image task completed" }]
|
|
|
|
# when: " == true"
|
|
|
|
dependencies: [trivy-image-scan, trivy-filesystem-scan]
|
2024-10-18 12:26:36 +00:00
|
|
|
|
2024-10-24 11:35:21 +00:00
|
|
|
- name: simple-container
|
|
|
|
inputs:
|
|
|
|
parameters:
|
|
|
|
- name: message
|
|
|
|
container:
|
|
|
|
image: alpine:latest
|
|
|
|
command: [sh, -c]
|
|
|
|
args: ["echo {{inputs.parameters.message}}"]
|
2024-10-23 15:03:17 +00:00
|
|
|
|
2024-10-24 11:35:21 +00:00
|
|
|
- name: ls
|
|
|
|
container:
|
|
|
|
image: alpine:latest
|
|
|
|
command: [sh, -c]
|
|
|
|
args: [ls /]
|
|
|
|
|
|
|
|
- name: git-clone
|
|
|
|
container:
|
|
|
|
image: ubuntu:latest
|
|
|
|
command: [sh, -c]
|
|
|
|
args:
|
|
|
|
- |
|
|
|
|
apt update
|
|
|
|
apt install -y git
|
|
|
|
git clone -b main https://forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/Franz.Germann/fibonacci_go.git /shared-data/repo
|
|
|
|
ls -la /
|
|
|
|
ls -la /shared-data
|
|
|
|
ls -la /shared-data/repo
|
|
|
|
volumeMounts:
|
|
|
|
- name: shared-data
|
|
|
|
mountPath: /shared-data
|
|
|
|
|
|
|
|
- name: build
|
|
|
|
container:
|
|
|
|
image: gcr.io/kaniko-project/executor:v1.23.2
|
|
|
|
args:
|
|
|
|
[
|
|
|
|
"--dockerfile=/shared-data/repo/Dockerfile",
|
|
|
|
"--context=/shared-data/repo/",
|
|
|
|
"--destination=forgejo.edf-bootstrap.cx.fg1.ffm.osc.live/franz.germann/fibonacci_go:latest",
|
|
|
|
]
|
|
|
|
volumeMounts:
|
|
|
|
- name: shared-data
|
|
|
|
mountPath: /shared-data
|
|
|
|
- name: docker-config
|
|
|
|
mountPath: /kaniko/.docker
|
|
|
|
|
|
|
|
- name: unit-tests
|
|
|
|
container:
|
|
|
|
image: golang:1.23.2
|
|
|
|
command: [sh, -c]
|
|
|
|
args:
|
|
|
|
- |
|
|
|
|
cd /shared-data/repo && \
|
|
|
|
go test ./... -v > test-results.txt; \
|
|
|
|
cat test-results.txt
|
|
|
|
volumeMounts:
|
|
|
|
- name: shared-data
|
|
|
|
mountPath: /shared-data
|
|
|
|
# How to extract artifacts
|
|
|
|
|
|
|
|
- name: lint-scan
|
|
|
|
container:
|
|
|
|
image: golangci/golangci-lint:v1.61.0
|
|
|
|
command: [sh, -c]
|
|
|
|
args:
|
|
|
|
- |
|
|
|
|
cd /shared-data/repo && \
|
|
|
|
golangci-lint run ./... --out-format=json --timeout 5m > lint-results.json; \
|
|
|
|
cat lint-results.json
|
|
|
|
volumeMounts:
|
|
|
|
- name: shared-data
|
|
|
|
mountPath: /shared-data
|