Prepared first working workflow version to auto build docker images
This commit is contained in:
parent
2a80c733b3
commit
37ea900325
@ -4,6 +4,16 @@ metadata:
|
|||||||
generateName: build-workflow-
|
generateName: build-workflow-
|
||||||
spec:
|
spec:
|
||||||
entrypoint: main
|
entrypoint: main
|
||||||
|
arguments:
|
||||||
|
parameters:
|
||||||
|
- name: repo
|
||||||
|
value: https://gitea.marcin00.pl/pikram/user-microservice.git
|
||||||
|
- name: branch
|
||||||
|
value: main
|
||||||
|
- name: image
|
||||||
|
value: marcin00.azurecr.io/user-microservice:{{workflow.uid}}
|
||||||
|
- name: registry_server
|
||||||
|
value: marcin00.azurecr.io
|
||||||
serviceAccountName: edu-agentpool
|
serviceAccountName: edu-agentpool
|
||||||
volumeClaimTemplates:
|
volumeClaimTemplates:
|
||||||
- metadata:
|
- metadata:
|
||||||
@ -12,42 +22,54 @@ spec:
|
|||||||
accessModes: [ "ReadWriteOnce" ]
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 1Gi
|
storage: 128Mi
|
||||||
templates:
|
templates:
|
||||||
|
|
||||||
# 🔁 Main steps sequence
|
# 🔁 Main steps sequence
|
||||||
- name: main
|
- name: main
|
||||||
steps:
|
steps:
|
||||||
- - name: checkout
|
- - name: checkout
|
||||||
template: git-checkout
|
template: checkout
|
||||||
arguments: {}
|
arguments:
|
||||||
- - name: test-python
|
parameters:
|
||||||
template: python-tests
|
- name: repo
|
||||||
- - name: build-and-test-image
|
value: "{{workflow.parameters.repo}}"
|
||||||
template: docker-goss-test
|
- name: branch
|
||||||
- - name: deploy
|
value: "{{workflow.parameters.branch}}"
|
||||||
template: push-docker-image
|
- - name: tests
|
||||||
|
template: tests
|
||||||
|
- - name: build-test-and-push-image
|
||||||
|
template: build-test-and-push-image
|
||||||
|
|
||||||
# 📦 GIT CHECKOUT
|
# 📦 GIT CHECKOUT
|
||||||
- name: git-checkout
|
- name: checkout
|
||||||
script:
|
inputs:
|
||||||
|
parameters:
|
||||||
|
- name: repo
|
||||||
|
- name: branch
|
||||||
|
container:
|
||||||
image: alpine/git
|
image: alpine/git
|
||||||
command: [sh]
|
workingDir: /workspace
|
||||||
source: |
|
args:
|
||||||
git clone https://gitea.marcin00.pl/pikram/user-microservice.git /workspace/repo
|
- clone
|
||||||
cd /workspace/repo
|
- --depth
|
||||||
git checkout main
|
- "1"
|
||||||
|
- --branch
|
||||||
|
- "{{inputs.parameters.branch}}"
|
||||||
|
- --single-branch
|
||||||
|
- "{{inputs.parameters.repo}}"
|
||||||
|
- repo
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: workspace
|
- name: workspace
|
||||||
mountPath: /workspace
|
mountPath: /workspace
|
||||||
|
|
||||||
# 🧪 PYTHON TESTS
|
# 🧪 PYTHON TESTS
|
||||||
- name: python-tests
|
- name: tests
|
||||||
script:
|
script:
|
||||||
image: python:3.11.7-alpine
|
image: python:3.11.7-alpine
|
||||||
command: [sh]
|
command: [sh]
|
||||||
|
workingDir: /workspace/repo/api
|
||||||
source: |
|
source: |
|
||||||
cd /workspace/repo/api
|
|
||||||
python3 -m venv env
|
python3 -m venv env
|
||||||
. env/bin/activate
|
. env/bin/activate
|
||||||
pip install -r requirements.txt pytest
|
pip install -r requirements.txt pytest
|
||||||
@ -57,43 +79,51 @@ spec:
|
|||||||
mountPath: /workspace
|
mountPath: /workspace
|
||||||
|
|
||||||
# 🐳 BUILDS AND GOSS TESTS
|
# 🐳 BUILDS AND GOSS TESTS
|
||||||
- name: docker-goss-test
|
- name: build-test-and-push-image
|
||||||
script:
|
container:
|
||||||
image: docker:cli
|
image: docker:dind
|
||||||
command: [sh]
|
command: [sh, -c]
|
||||||
source: |
|
workingDir: /workspace/repo
|
||||||
cd /workspace/repo
|
args:
|
||||||
docker build -t ${DOCKER_IMAGE} .
|
- |
|
||||||
|
dockerd-entrypoint.sh &
|
||||||
|
sleep 3
|
||||||
|
docker build -t {{workflow.parameters.image}} .
|
||||||
|
|
||||||
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -o goss
|
apk add --no-cache bash
|
||||||
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -o dgoss
|
|
||||||
|
wget https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -O goss
|
||||||
|
wget https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -O dgoss
|
||||||
chmod +rx *goss
|
chmod +rx *goss
|
||||||
|
|
||||||
export GOSS_OPTS="-f junit"
|
export GOSS_OPTS="-f junit"
|
||||||
export GOSS_PATH=./goss
|
export GOSS_PATH=./goss
|
||||||
export GOSS_SLEEP=3
|
export GOSS_SLEEP=3
|
||||||
./dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: ${DOCKER_IMAGE} > /workspace/goss_junit.xml
|
./dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: {{workflow.parameters.image}} > /workspace/goss_junit.xml
|
||||||
env:
|
|
||||||
- name: DOCKER_IMAGE
|
|
||||||
value: marcin00.azurecr.io/user-microservice:$(WORKFLOW_ID)
|
|
||||||
volumeMounts:
|
|
||||||
- name: workspace
|
|
||||||
mountPath: /workspace
|
|
||||||
|
|
||||||
# 🚀 DEPLOY
|
echo "===> Logging into ACR"
|
||||||
- name: push-docker-image
|
echo "$ACR_PASSWORD" | docker login {{workflow.parameters.registry_server}} -u $ACR_USERNAME --password-stdin
|
||||||
script:
|
|
||||||
image: mcr.microsoft.com/azure-cli
|
echo "===> Pushing image to ACR"
|
||||||
command: [sh]
|
docker push {{workflow.parameters.image}}
|
||||||
source: |
|
|
||||||
az login --identity
|
|
||||||
az acr login --name ${ACR_NAME}
|
|
||||||
docker push ${DOCKER_IMAGE}
|
|
||||||
env:
|
env:
|
||||||
- name: ACR_NAME
|
- name: ACR_USERNAME
|
||||||
value: marcin00
|
valueFrom:
|
||||||
- name: DOCKER_IMAGE
|
secretKeyRef:
|
||||||
value: marcin00.azurecr.io/user-microservice:$(WORKFLOW_ID)
|
name: acr-creds
|
||||||
|
key: username
|
||||||
|
- name: ACR_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: acr-creds
|
||||||
|
key: password
|
||||||
|
securityContext:
|
||||||
|
privileged: true
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: workspace
|
- name: workspace
|
||||||
mountPath: /workspace
|
mountPath: /workspace
|
||||||
|
- name: docker-library
|
||||||
|
mountPath: /var/lib/docker
|
||||||
|
volumes:
|
||||||
|
- name: docker-library
|
||||||
|
emptyDir: {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user