diff --git a/argo-workflows/build.yaml b/argo-workflows/build.yaml index a73b394..4772dfe 100644 --- a/argo-workflows/build.yaml +++ b/argo-workflows/build.yaml @@ -11,7 +11,7 @@ spec: - name: branch value: main - name: image - value: marcin00.azurecr.io/user-microservice:{{workflow.uid}} + value: marcin00.azurecr.io/user-microservice - name: registry_server value: marcin00.azurecr.io serviceAccountName: edu-agentpool @@ -36,10 +36,16 @@ spec: value: "{{workflow.parameters.repo}}" - name: branch value: "{{workflow.parameters.branch}}" + - - name: get-git-sha + template: get-git-sha - - name: tests template: tests - - name: build-test-and-push-image template: build-test-and-push-image + arguments: + parameters: + - name: git-sha + value: "{{steps.get-git-sha.outputs.parameters.git-sha}}" # ๐Ÿ“ฆ GIT CHECKOUT - name: checkout @@ -63,6 +69,23 @@ spec: - name: workspace mountPath: /workspace +# Get sha of the latest commit + - name: get-git-sha + script: + image: alpine/git + command: [sh] + workingDir: /workspace/repo + source: | + git rev-parse HEAD > /tmp/gitsha.txt + volumeMounts: + - name: workspace + mountPath: /workspace + outputs: + parameters: + - name: git-sha + valueFrom: + path: /tmp/gitsha.txt + # ๐Ÿงช PYTHON TESTS - name: tests script: @@ -80,6 +103,9 @@ spec: # ๐Ÿณ BUILDS AND GOSS TESTS - name: build-test-and-push-image + inputs: + parameters: + - name: git-sha container: image: docker:dind command: [sh, -c] @@ -88,7 +114,8 @@ spec: - | dockerd-entrypoint.sh & sleep 3 - docker build -t {{workflow.parameters.image}} . + DOCKER_IMAGE={{workflow.parameters.image}}:{{inputs.parameters.git-sha}} + docker build -t $DOCKER_IMAGE . apk add --no-cache bash @@ -99,13 +126,13 @@ spec: export GOSS_OPTS="-f junit" export GOSS_PATH=./goss export GOSS_SLEEP=3 - ./dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: {{workflow.parameters.image}} > /workspace/goss_junit.xml + ./dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: $DOCKER_IMAGE > /workspace/goss_junit.xml echo "===> Logging into ACR" echo "$ACR_PASSWORD" | docker login {{workflow.parameters.registry_server}} -u $ACR_USERNAME --password-stdin echo "===> Pushing image to ACR" - docker push {{workflow.parameters.image}} + docker push $DOCKER_IMAGE env: - name: ACR_USERNAME valueFrom: