Skip to content

Commit e492faa

Browse files
committed
FEAT-052: Push containers with tags equal to both the release version, and the git tag.
1 parent 1f472e1 commit e492faa

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

jobs/hook_container.yml

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,74 @@
1313
name={{ artefact_dir }}
1414
state=directory
1515

16-
- name: Obtain the current tag, (or version if untagged) of this repository.
17-
shell: |
18-
TAG=$(git name-rev --tags --name-only HEAD | cut -f1 -d^)
19-
if [ "$(echo $TAG | tr -d [:space:])" == "undefined" ]; then
20-
git rev-parse --short HEAD
21-
else
22-
echo $TAG
23-
fi
16+
- name: Obtain current tag of this repository, if any.
17+
shell: git name-rev --tags --name-only HEAD | cut -f1 -d^
2418
args:
2519
chdir: "{{ container_dir }}"
2620
executable: /bin/bash
27-
register: current_version
21+
register: tag
2822

29-
- name: Set artefact name.
23+
- name: Obtain current version hash of this repository.
24+
shell: git rev-parse --short HEAD
25+
args:
26+
chdir: "{{ container_dir }}"
27+
executable: /bin/bash
28+
register: version
29+
30+
- name: Obtain current branch of this repository.
31+
shell: git describe --all | grep -o [^/]*$
32+
args:
33+
chdir: "{{ container_dir }}"
34+
executable: /bin/bash
35+
register: branch
36+
37+
# Exporting container filesystem as tarball.
38+
39+
- name: Set artefact name with tag, if we could find one.
40+
set_fact:
41+
artefact_name: "{{ container_name }}_{{ tag.stdout }}.tar"
42+
when: tag.stdout != "undefined"
43+
44+
- name: Set artefact name with version hash, if we could not find a tag.
3045
set_fact:
31-
artefact_name: "{{ container_name }}_{{ current_version.stdout }}.tar"
46+
artefact_name: "{{ container_name }}_{{ version.stdout }}.tar"
47+
when: tag.stdout == "undefined"
3248

3349
- name: Export the container filesystem as an artefact.
3450
command: docker export --output={{ artefact_dir }}{{ artefact_name }} {{ container_name }}
3551
args:
3652
creates: "{{ artefact_dir }}{{ artefact_name }}"
3753

38-
- name: Obtain the current tag (or branch if untagged) of this repository.
39-
shell: |
40-
TAG=$(git name-rev --tags --name-only HEAD | cut -f1 -d^)
41-
if [ "$(echo $TAG | tr -d [:space:])" == "undefined" ]; then
42-
git describe --all | grep -o [^/]*$
43-
else
44-
echo $TAG
45-
fi
46-
args:
47-
chdir: "{{ container_dir }}"
48-
executable: /bin/bash
49-
register: current_branch
54+
# Storing container with tag=branch.
5055

51-
- name: Define the name used for the output Docker image
56+
- name: Define the name used for the output Docker image using the branch.
5257
set_fact:
53-
output_image_name: virtualmicromagnetics/{{ container_name }}:{{ current_branch.stdout }}
58+
output_image_name_branch: virtualmicromagnetics/{{ container_name }}:{{ branch.stdout }}
5459

5560
- name: Create a Docker image from our provisioned container.
56-
command: docker commit {{ container_name }} {{ output_image_name }}
61+
command: docker commit {{ container_name }} {{ output_image_name_branch }}
5762

58-
- name: Push the Docker image.
59-
command: docker push {{ output_image_name }}
63+
- name: Push the Docker image with tag equal to branch.
64+
command: docker push {{ output_image_name_branch }}
6065
when: container_push
6166

67+
# Storing container with tag=tag.
68+
69+
- name: Define the name used for the output Docker image using the branch.
70+
set_fact:
71+
output_image_name_tag: virtualmicromagnetics/{{ container_name }}:{{ tag.stdout }}
72+
when: tag.stdout != "undefined"
73+
74+
- name: Create a Docker image from our provisioned container.
75+
command: docker commit {{ container_name }} {{ output_image_name_tag }}
76+
when: tag.stdout != "undefined"
77+
78+
- name: Push the Docker image with tag equal to branch.
79+
command: docker push {{ output_image_name_tag }}
80+
when: container_push and (tag.stdout != "undefined")
81+
82+
# Remove the evidence.
83+
6284
- name: Destroy the container.
6385
command: vagrant destroy --force
6486
chdir={{ container_dir }}

0 commit comments

Comments
 (0)