-
Notifications
You must be signed in to change notification settings - Fork 15
/
action.yml
164 lines (153 loc) · 7.42 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: 'Build Action Server image'
description: 'Build a Docker image with custom actions for Rasa Action Server'
inputs:
actions_directory:
description: "Path to the directory with actions."
default: "${{ github.workspace }}/actions"
required: false
requirements_file:
description: "Path to the requirements.txt file."
required: false
docker_registry:
description: "Name of the docker registry which the Docker image should be published to."
default: "docker.io"
required: false
docker_registry_login:
description: "Login name for the Docker registry."
required: true
docker_registry_password:
description: "Password for the Docker registry."
required: true
docker_image_name:
description: "Docker image name."
default: "action_server"
required: false
docker_image_tag:
description: "Docker image tag."
default: ${{ github.run_id }}
required: false
docker_registry_push:
description: "Push a docker image to the registry. If `False` the user can add manual extra steps in their workflow which use the built image."
default: "true"
required: false
dockerfile:
description: "Path to a custom Dockerfile."
required: false
rasa_sdk_version:
description: "Version of the Rasa SDK which should be used to build the image."
default: "latest"
required: false
docker_build_args:
description: "List of build-time variables."
required: false
outputs:
docker_image_name:
description: "Docker image name, the name contains the registry address and the image name, e.g., `docker.io/my_account/my_image_name`."
value: ${{ steps.set-output.outputs.docker_image_name }}
docker_image_tag:
description: "Tag of the image, e.g., `v1.0`."
value: ${{ steps.set-output.outputs.docker_image_tag }}
docker_image_full_name:
description: "Docker image name (contains an address to the registry, image name, and tag), e.g., `docker.io/my_account/my_image_name:v1.0`."
value: ${{ steps.set-output.outputs.docker_image_full_name }}
branding:
icon: 'layers'
color: 'blue'
runs:
using: "composite"
steps:
- name: Set environment variables
shell: bash
run: |-
# Set Dockerfile
if [[ "${{ inputs.dockerfile }}" == "" ]]; then
echo "DOCKERFILE=${{ github.action_path }}/default_files/Dockerfile" >> $GITHUB_ENV
else
echo "DOCKERFILE=${{ inputs.dockerfile }}" >> $GITHUB_ENV
fi
# Set DOCKER_IMAGE_FULL_NAME
echo "DOCKER_IMAGE_FULL_NAME=${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}:${{ inputs.docker_image_tag }}" >> $GITHUB_ENV
- name: Copy files
shell: bash
run: |
# Set a path for the requirements.txt file
mkdir -p ${{ github.workspace }}/tmp
if [[ "${{ inputs.requirements_file }}" == "" ]]; then
# Check if requirements file exists
if [[ -d ${{ inputs.actions_directory }}/requirements.txt ]]; then
cp -a ${{ inputs.actions_directory }}/requirements.txt ${{ github.workspace }}/tmp/requirements.txt
else
# Copy default files into the tmp directory
cp -a ${{ github.action_path }}/default_files/requirements.txt ${{ github.workspace }}/tmp/requirements.txt
fi
else
cp -a ${{ inputs.requirements_file }} ${{ github.workspace }}/tmp/requirements.txt || echo "::error::The requirements file (${{ inputs.requirements_file }}) doesn't exist."
fi
# Copy the actions directory into the tmp directory
mkdir -p ${{ github.workspace }}/tmp/actions
if [[ ! -d ${{ inputs.actions_directory }} ]]; then
echo "::error::The actions directory (${{ inputs.actions_directory }}) doesn't exist." && exit 1
fi
cp -a ${{ inputs.actions_directory }}/* ${{ github.workspace }}/tmp/actions/
- name: Set the Rasa SDK version
shell: bash
run: |
DOCKERHUB_TAGS_URL="https://registry.hub.docker.com/v2/repositories/rasa/rasa-sdk/tags?page_size=10000"
# Get the latest version
if [[ "${{ inputs.rasa_sdk_version }}" == "latest" ]]; then
LATEST_RASA_SDK_VERSION=$(curl -sL ${DOCKERHUB_TAGS_URL} | jq -r '.results[].name' | grep -vE 'refs|aws|latest' | sort -Vr | head -n1)
echo "RASA_SDK_VERSION=${LATEST_RASA_SDK_VERSION}" >> $GITHUB_ENV
else
# Validate Rasa SDK version
CHECK_VERSION=$(curl --silent ${DOCKERHUB_TAGS_URL} | jq -r '.results[] | select(.name=="${{ inputs.rasa_sdk_version }}") | .name')
if [[ "$CHECK_VERSION" != "${{ inputs.rasa_sdk_version }}" ]]; then
echo "::error::Rasa SDK in ${{ inputs.rasa_sdk_version }} version doesn't exist. Check if the given Rasa SDK version is valid, https://hub.docker.com/r/rasa/rasa-sdk/tags" && exit 1
fi
echo "RASA_SDK_VERSION=${{ inputs.rasa_sdk_version }}" >> $GITHUB_ENV
fi
- name: Docker login
run: |-
if [[ "${{ inputs.docker_registry_login}}" != "" ]] && [[ "${{ inputs.docker_registry_password }}" != "" ]]; then
echo "Login to the ${{ inputs.docker_registry }} registry."
echo "${{ inputs.docker_registry_password }}" | docker login ${{ inputs.docker_registry }} -u ${{ inputs.docker_registry_login }} --password-stdin
elif [[ "${{ inputs.docker_registry_login}}" == "" ]] || [[ "${{ inputs.docker_registry_password }}" == "" ]]; then
echo "::warning::You have to pass the docker_registry_login and docker_registry_password input parameters in order to log in to the ${{ inputs.docker_registry }} registry."
fi
shell: bash
- name: Docker build
run: |-
echo "Building a docker image using Rasa SDK in ${{ env.RASA_SDK_VERSION }} version."
echo " Dockerfile arguments:"
echo " GITHUB_SHA: $GITHUB_SHA"
echo " GITHUB_REF: $GITHUB_REF"
echo " DOCKER_IMAGE_NAME: ${{ inputs.docker_image_name }}"
echo " DOCKER_IMAGE_TAG: ${{ inputs.docker_image_tag }}"
echo " RASA_SDK_VERSION: ${{ env.RASA_SDK_VERSION }}"
echo ""
echo " Docker build extra arguments: ${{ inputs.docker_build_args}}"
echo ""
docker build \
--tag "${{ env.DOCKER_IMAGE_FULL_NAME }}" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
--build-arg DOCKER_IMAGE_NAME="${{ inputs.docker_image_name }}" \
--build-arg RASA_SDK_VERSION="${{ env.RASA_SDK_VERSION }}" \
--build-arg DOCKER_IMAGE_TAG="${{ inputs.docker_image_tag }}" ${{ inputs.docker_build_args }}\
-f ${{ env.DOCKERFILE }} ${{ github.workspace }}
shell: bash
- name: Docker push
shell: bash
run: |
if [[ "${{ inputs.docker_registry_push}}" == "true" ]]; then
echo "Pushing the ${{ env.DOCKER_IMAGE_FULL_NAME }} image into the registry..."
docker push ${{ env.DOCKER_IMAGE_FULL_NAME }}
else
echo "The image won't be pushed into the repository. The docker_registry_push input parameter has to be set to 'true' in order to push the docker image."
fi
- name: Set outputs
id: set-output
run: |
echo "::set-output name=docker_image_name::${{ inputs.docker_registry }}/${{ inputs.docker_image_name }}"
echo "::set-output name=docker_image_tag::${{ inputs.docker_image_tag }}"
echo "::set-output name=docker_image_full_name::${{ env.DOCKER_IMAGE_FULL_NAME }}"
shell: bash