Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnixPB: Add latest commit SHA to ansible.log file #2751

Merged
merged 20 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
uses: docker/build-push-action@v2
with:
file: ./ansible/docker/Dockerfile.CentOS6
build-args: git_sha=${{ github.sha }}
tags: adoptopenjdk/centos6_build_image:latest
cache-from: type=registry,ref=adoptopenjdk/centos6_build_image:latest
cache-to: type=inline
Expand All @@ -57,6 +58,7 @@ jobs:
uses: docker/build-push-action@v2
with:
file: ./ansible/docker/Dockerfile.Alpine3
build-args: git_sha=${{ github.sha }}
tags: adoptopenjdk/alpine3_build_image:latest
cache-from: type=registry,ref=adoptopenjdk/alpine3_build_image:latest
cache-to: type=inline
Expand Down
12 changes: 7 additions & 5 deletions ansible/docker/Dockerfile.Alpine3
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM alpine:3.15

ARG git_sha

RUN apk update \
&& apk upgrade \
&& apk add ansible

COPY . /ansible
COPY ../. /infrastructure

RUN echo "localhost ansible_connection=local" > /ansible/hosts
RUN echo "localhost ansible_connection=local" > /infrastructure/ansible/hosts

RUN set -eux; \
cd /ansible; \
ansible-playbook -i hosts ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml --skip-tags="debug,hosts_file,hostname,adoptopenjdk,jenkins,nagios,superuser,docker,swap_file,crontab,nvidia_cuda_toolkit"; \
rm -rf /ansible; apk del ansible
cd /infrastructure; \
ansible-playbook -i ansible/hosts ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml -e "git_sha=$git_sha" --skip-tags="debug,hosts_file,hostname,adoptopenjdk,jenkins,nagios,superuser,docker,swap_file,crontab,nvidia_cuda_toolkit"; \
rm -rf /infrastructure; apk del ansible

ENV \
JDK7_BOOT_DIR="/usr/lib/jvm/jdk8" \
Expand Down
13 changes: 7 additions & 6 deletions ansible/docker/Dockerfile.CentOS6
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM centos:6.9

ARG git_sha
ARG user=jenkins

# Install Python 3
Expand All @@ -9,16 +10,16 @@ RUN sed -i -e 's!mirrorlist!#mirrorlist!g' /etc/yum.repos.d/CentOS-Base.repo; \
yum -y install gcc openssl-devel bzip2-devel sqlite-devel sudo wget python3 epel-release; \
yum -y install ansible

COPY . /ansible
COPY ../. /infrastructure

RUN echo "localhost ansible_connection=local" > /ansible/hosts
RUN echo "localhost ansible_connection=local" > /infrastructure/ansible/hosts

RUN set -eux; \
cd /ansible; \
ansible-playbook -i hosts ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml --skip-tags="debug,hosts_file,hostname,adoptopenjdk,jenkins,nagios,superuser,docker,swap_file,crontab,nvidia_cuda_toolkit"; \
ansible-playbook -i hosts ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml --tags="riscv"
cd /infrastructure; \
ansible-playbook -i ansible/hosts ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml -e "git_sha=$git_sha" --skip-tags="debug,hosts_file,hostname,adoptopenjdk,jenkins,nagios,superuser,docker,swap_file,crontab,nvidia_cuda_toolkit"; \
ansible-playbook -i ansible/hosts ansible/playbooks/AdoptOpenJDK_Unix_Playbook/main.yml -e "git_sha=$git_sha" --tags="riscv"

RUN rm -rf /ansible; yum remove -y ansible; yum clean all
RUN rm -rf /infrastructure; yum remove -y ansible; yum clean all

RUN groupadd -g 1000 ${user}
RUN useradd -c "Jenkins user" -d /home/${user} -u 1000 -g 1000 -m ${user}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,3 @@
state: present
backup: yes
tags: hosts_file, adoptopenjdk

# This doesn't work as ansible says it can't write to the directory
# Leaving this here in case someoen can make it work in the future
#
#- name: Record playbook completion with time in /var/log/ansiblerun.log
# lineinfile:
# state: present
# create: yes
# path: /var/tmp/ansiblerun.log
# mode: 0644
# line: "{{ ansible_date_time.iso8601_basic_short }} END"
# tags: ansiblerunlog

# Version of the above that works
- name: Record playbook completion with time in /var/log/ansiblerun.log
command: echo $(date +%Y%m%dT%H%M%S) >> /var/log/ansiblerun.log
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
---
# Updates $HOME/ansible.log with the date and time of latest ansible playbook run

- name: Set variables (Linux)
- name: Set Log path
set_fact:
home_path: /home/{{ Jenkins_Username }}
user_group: "{{ Jenkins_Username }}"
when:
- ansible_distribution != "MacOSX"
- ansible_distribution != "Solaris"
log_path: /var/log

- name: Set variables (MacOS)
set_fact:
home_path: /Users/{{ Jenkins_Username }}
user_group: "staff"
when:
- ansible_distribution == "MacOSX"

- name: Set variables (Solaris)
- name: Set variables (Not MacOS)
set_fact:
home_path: /export/home/{{ Jenkins_Username }}
user_group: "{{ Jenkins_Username }}"
user_group: "root"
when:
- ansible_distribution == "Solaris"
- ansible_distribution != "MacOSX"

- name: Check if Jenkins user exists
stat:
path: "{{ home_path }}"
register: home_exists
- name: Get Latest git commit SHA
shell: git rev-parse HEAD
register: git_output
delegate_to: localhost
ignore_errors: yes
when: git_sha is not defined

- name: Set git_output to git_sha
set_fact:
git_sha: "{{ git_output.stdout }}"
when: git_sha is not defined

- name: Update Log File
lineinfile:
owner: "{{ Jenkins_Username }}"
owner: root
group: "{{ user_group }}"
create: yes
path: "{{ home_path }}/ansible.log"
path: "{{ log_path }}/ansible.log"
insertafter: EOF
line: "{{ ansible_date_time.date }} -- {{ ansible_date_time.time }}"
line: "{{ ansible_date_time.date }} {{ ansible_date_time.time }} {{ git_sha }}"
become: yes
become_user: root
when: home_exists.stat.exists