Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Apr 6, 2023
2 parents 381925c + 3d042c6 commit 0637f29
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 92 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version:
@bash ./cicd/version/version.sh -g . -c
@bash cicd/version/version.sh -g . -c

version-full:
@bash ./cicd/version/version.sh -g . -c -m
@bash cicd/version/version.sh -g . -c -m
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ Take the assumption we want to host a specific instance pool to ARM servers.
# values.yaml
pipelines:
pool: Kubernetes
capabiliies:
- arch-arm64

affinity:
nodeAffinity:
Expand All @@ -112,7 +110,7 @@ pool:
name: Kubernetes
demands:
- Agent.OS -equals Linux
- arch-arm64
- Agent.OSArchitecture -equals ARM64

stages:
...
Expand Down Expand Up @@ -143,6 +141,7 @@ stages:
| `pipelines.capabiliies` | Add [demands/capabilities](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml) to the agent | `[]` |
| `pipelines.pat` | Personal Access Token (PAT) used by the agent to connect. | *None* |
| `pipelines.pool` | Agent pool to which the Agent should register. | *None* |
| `pipelines.timeout` | Time in seconds after a agent will be stopped, the same amount of time is applied as a timeout for the system to shut down. | `3600` (1 hour) |
| `pipelines.url` | The Azure base URL for your organization | *None* |
| `pipelines.workDir` | The work directory the agent should use | `_work` |
| `resources` | Resource limits | `{ "resources": { "limits": { "cpu": 2, "memory": "4Gi" }, "requests": { "cpu": 1, "memory": "2Gi" } }}` |
Expand Down
14 changes: 7 additions & 7 deletions src/docker/Dockerfile-bullseye
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN apt-get update -q \
# Copy helper script, then verify installation
COPY arch.sh .
RUN chmod +x arch.sh \
&& ./arch.sh
&& bash arch.sh

# Install Azure CLI, then verify installation
RUN python3 -m pip install --upgrade pip setuptools wheel \
Expand All @@ -53,7 +53,7 @@ RUN python3 -m pip install --upgrade pip setuptools wheel \
ARG POWERSHELL_VERSION
ENV POWERSHELL_VERSION ${POWERSHELL_VERSION}
RUN mkdir -p /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(./arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(bash arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& chmod +x /opt/microsoft/powershell/pwsh \
&& ln -s /opt/microsoft/powershell/pwsh /usr/bin/pwsh \
&& pwsh -Version
Expand All @@ -63,15 +63,15 @@ ARG AGENT_VERSION
ENV AGENT_VERSION ${AGENT_VERSION}
ENV AGENT_HOME /azp
RUN mkdir -p ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(./arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(bash arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& cd $AGENT_HOME \
&& chmod +x ./run-docker.sh ./config.sh \
&& AGENT_ALLOW_RUNASROOT="1" ./run-docker.sh --version
&& chmod +x run-docker.sh config.sh \
&& AGENT_ALLOW_RUNASROOT="1" bash run-docker.sh --version

# Install YQ, then verify installation
ARG YQ_VERSION
ENV YQ_VERSION ${YQ_VERSION}
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 ./arch.sh) -o /usr/bin/yq \
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 bash arch.sh) -o /usr/bin/yq \
&& chmod +x /usr/bin/yq \
&& yq --version

Expand All @@ -85,4 +85,4 @@ WORKDIR ${AGENT_HOME}
COPY start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]
CMD bash start.sh
14 changes: 7 additions & 7 deletions src/docker/Dockerfile-focal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN apt-get update -q \
# Copy helper script, then verify installation
COPY arch.sh .
RUN chmod +x arch.sh \
&& ./arch.sh
&& bash arch.sh

# Install Azure CLI, then verify installation
RUN python3 -m pip install --upgrade pip setuptools wheel \
Expand All @@ -53,7 +53,7 @@ RUN python3 -m pip install --upgrade pip setuptools wheel \
ARG POWERSHELL_VERSION
ENV POWERSHELL_VERSION ${POWERSHELL_VERSION}
RUN mkdir -p /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(./arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(bash arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& chmod +x /opt/microsoft/powershell/pwsh \
&& ln -s /opt/microsoft/powershell/pwsh /usr/bin/pwsh \
&& pwsh -Version
Expand All @@ -63,15 +63,15 @@ ARG AGENT_VERSION
ENV AGENT_VERSION ${AGENT_VERSION}
ENV AGENT_HOME /azp
RUN mkdir -p ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(./arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(bash arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& cd $AGENT_HOME \
&& chmod +x ./run-docker.sh ./config.sh \
&& AGENT_ALLOW_RUNASROOT="1" ./run-docker.sh --version
&& chmod +x run-docker.sh config.sh \
&& AGENT_ALLOW_RUNASROOT="1" bash run-docker.sh --version

# Install YQ, then verify installation
ARG YQ_VERSION
ENV YQ_VERSION ${YQ_VERSION}
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 ./arch.sh) -o /usr/bin/yq \
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 bash arch.sh) -o /usr/bin/yq \
&& chmod +x /usr/bin/yq \
&& yq --version

Expand All @@ -85,4 +85,4 @@ WORKDIR ${AGENT_HOME}
COPY start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]
CMD bash start.sh
14 changes: 7 additions & 7 deletions src/docker/Dockerfile-jammy
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN apt-get update -q \
# Copy helper script, then verify installation
COPY arch.sh .
RUN chmod +x arch.sh \
&& ./arch.sh
&& bash arch.sh

# Install Azure CLI, then verify installation
RUN python3 -m pip install --upgrade pip setuptools wheel \
Expand All @@ -53,7 +53,7 @@ RUN python3 -m pip install --upgrade pip setuptools wheel \
ARG POWERSHELL_VERSION
ENV POWERSHELL_VERSION ${POWERSHELL_VERSION}
RUN mkdir -p /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(./arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(bash arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& chmod +x /opt/microsoft/powershell/pwsh \
&& ln -s /opt/microsoft/powershell/pwsh /usr/bin/pwsh \
&& pwsh -Version
Expand All @@ -63,15 +63,15 @@ ARG AGENT_VERSION
ENV AGENT_VERSION ${AGENT_VERSION}
ENV AGENT_HOME /azp
RUN mkdir -p ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(./arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(bash arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& cd $AGENT_HOME \
&& chmod +x ./run-docker.sh ./config.sh \
&& AGENT_ALLOW_RUNASROOT="1" ./run-docker.sh --version
&& chmod +x run-docker.sh config.sh \
&& AGENT_ALLOW_RUNASROOT="1" bash run-docker.sh --version

# Install YQ, then verify installation
ARG YQ_VERSION
ENV YQ_VERSION ${YQ_VERSION}
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 ./arch.sh) -o /usr/bin/yq \
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 bash arch.sh) -o /usr/bin/yq \
&& chmod +x /usr/bin/yq \
&& yq --version

Expand All @@ -85,4 +85,4 @@ WORKDIR ${AGENT_HOME}
COPY start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]
CMD bash start.sh
14 changes: 7 additions & 7 deletions src/docker/Dockerfile-ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ RUN python3 -m pip install --upgrade pip setuptools wheel \
# Copy helper script, then verify installation
COPY arch.sh .
RUN chmod +x arch.sh \
&& ./arch.sh
&& bash arch.sh

# Install Powershell, then verify installation
ARG POWERSHELL_VERSION
ENV POWERSHELL_VERSION ${POWERSHELL_VERSION}
RUN mkdir -p /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(./arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& curl -LsSf https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell-${POWERSHELL_VERSION}-linux-$(bash arch.sh).tar.gz | tar -xz -C /opt/microsoft/powershell \
&& chmod +x /opt/microsoft/powershell/pwsh \
&& ln -s /opt/microsoft/powershell/pwsh /usr/bin/pwsh \
&& pwsh -Version
Expand All @@ -61,15 +61,15 @@ ARG AGENT_VERSION
ENV AGENT_VERSION ${AGENT_VERSION}
ENV AGENT_HOME /azp
RUN mkdir -p ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(./arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& curl -LsSf https://vstsagentpackage.azureedge.net/agent/${AGENT_VERSION}/pipelines-agent-linux-$(bash arch.sh)-${AGENT_VERSION}.tar.gz | tar -xz -C ${AGENT_HOME} \
&& cd $AGENT_HOME \
&& chmod +x ./run-docker.sh ./config.sh \
&& AGENT_ALLOW_RUNASROOT="1" ./run-docker.sh --version
&& chmod +x run-docker.sh config.sh \
&& AGENT_ALLOW_RUNASROOT="1" bash run-docker.sh --version

# Install YQ, then verify installation
ARG YQ_VERSION
ENV YQ_VERSION ${YQ_VERSION}
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 ./arch.sh) -o /usr/bin/yq \
RUN curl -LsSf https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(ARCH_AMD64=amd64 bash arch.sh) -o /usr/bin/yq \
&& chmod +x /usr/bin/yq \
&& yq --version

Expand All @@ -83,4 +83,4 @@ WORKDIR ${AGENT_HOME}
COPY start.sh .
RUN chmod +x start.sh

CMD ["./start.sh"]
CMD bash start.sh
37 changes: 11 additions & 26 deletions src/docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ if [ -n "$AZP_WORK" ]; then
mkdir -p "$AZP_WORK"
fi

cleanup() {
if [ -e config.sh ]; then
print_header "Cleanup, removing agent..."

# If the agent has some running jobs, the configuration removal process will fail.
# So, give it some time to finish the job.
while true; do
./config.sh remove --unattended --auth PAT --token $(cat "$AZP_TOKEN_FILE") && break

echo "Retrying in 30 seconds..."
sleep 30
done
fi
}

print_header() {
lightcyan='\033[1;36m'
nocolor='\033[0m'
Expand All @@ -50,7 +35,7 @@ export AGENT_ALLOW_RUNASROOT="1"
# Let the agent ignore the token env variables
export VSO_AGENT_IGNORE=AZP_TOKEN,AZP_TOKEN_FILE

./config.sh \
bash config.sh \
--acceptTeeEula \
--agent "${AZP_AGENT_NAME:-$(hostname)}" \
--auth PAT \
Expand All @@ -59,17 +44,17 @@ export VSO_AGENT_IGNORE=AZP_TOKEN,AZP_TOKEN_FILE
--token $(cat "$AZP_TOKEN_FILE") \
--unattended \
--url "$AZP_URL" \
--work "${AZP_WORK:-_work}"
--work "${AZP_WORK:-_work}" &

print_header "Running agent..."
# Fake the exit code of the agent for the prevent Kubernetes to detect the pod as failed (this is intended)
# See: https://stackoverflow.com/a/62183992/12732154
wait $!

if ! grep -q "template" <<<"$AZP_AGENT_NAME"; then
echo "Cleanup traps enabled."
print_header "Running agent..."

trap 'cleanup; exit 0' EXIT
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
fi
# Running it with the --once flag at the end will shut down the agent after the build is executed
bash run-docker.sh "$@" --once &

# To be aware of TERM and INT signals call "run-docker.sh", running it with the --once flag at the end will shut down the agent after the build is executed
./run-docker.sh "$@" --once
# Fake the exit code of the agent for the prevent Kubernetes to detect the pod as failed (this is intended)
# See: https://stackoverflow.com/a/62183992/12732154
wait $!
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
apiVersion: apps/v1
kind: StatefulSet
kind: Deployment
metadata:
name: {{ include "this.fullname" . }}
labels:
{{- include "this.labels" . | nindent 4 }}
spec:
podManagementPolicy: Parallel
{{- if not (and (.Values.autoscaling.enabled) (.Capabilities.APIVersions.Has "keda.sh/v1alpha1")) }}
replicas: {{ .Values.autoscaling.minReplicas }}
{{- end }}
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 100%
maxUnavailable: 0
replicas: {{ .Values.autoscaling.minReplicas | int | required "A value for .Values.autoscaling.minReplicas is required" }}
selector:
matchLabels:
{{- include "this.selectorLabels" . | nindent 6 }}
serviceName: {{ include "this.fullname" . }}
template:
metadata:
labels:
Expand All @@ -31,7 +32,7 @@ spec:
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.autoscaling.cooldown }}
terminationGracePeriodSeconds: {{ .Values.pipelines.timeout | int | required "A value for .Values.pipelines.timeout is required" }}
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down Expand Up @@ -66,15 +67,18 @@ spec:
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: workdir
mountPath: {{ .Values.pipelines.workDir | quote }}
{{- with .Values.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.extraVolumes }}
volumes:
{{- toYaml .Values.extraVolumes | nindent 8 }}
- name: workdir
ephemeral:
volumeClaimTemplate:
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: {{ .Values.pipelines.cacheType | required "A value for .Values.pipelines.cacheType is required" }}
resources:
requests:
storage: {{ .Values.pipelines.cacheSize | required "A value for .Values.pipelines.cacheSize is required" }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
Expand All @@ -88,12 +92,3 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumeClaimTemplates:
- metadata:
name: workdir
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: {{ .Values.pipelines.cacheType | required "A value for .Values.pipelines.cacheType is required" }}
resources:
requests:
storage: {{ .Values.pipelines.cacheSize | required "A value for .Values.pipelines.cacheSize is required" }}
Loading

0 comments on commit 0637f29

Please sign in to comment.