Skip to content

Commit cd44703

Browse files
committed
FEA: Add GitHub action
1 parent e9a9658 commit cd44703

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.10.7-slim
2+
3+
# Install poetry.
4+
ENV POETRY_HOME=/root/.poetry
5+
ENV PATH "$POETRY_HOME/bin:$PATH"
6+
RUN curl -sSL https://install.python-poetry.org | python3 - && poetry config virtualenvs.create false;
7+
8+
COPY get_deployment_info/entrypoint.sh /entrypoint.sh
9+
10+
RUN chmod +x entrypoint.sh
11+
12+
ENTRYPOINT ["/entrypoint.sh"]

action.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: 'Get deployment information'
2+
description: "Get the information required to build and deploy an Octue service."
3+
author: 'cortadocodes'
4+
#branding:
5+
# icon: git-pull-request
6+
# color: green
7+
inputs:
8+
gcp_project_name:
9+
description: ''
10+
required: true
11+
gcp_project_number:
12+
description: ''
13+
required: true
14+
gcp_region:
15+
description: ''
16+
required: true
17+
gcp_resource_affix:
18+
description: ''
19+
required: true
20+
gcp_environment:
21+
description: ''
22+
required: false
23+
default: main
24+
gcp_service:
25+
description: ''
26+
required: true
27+
28+
outputs:
29+
branch_tag_kebab:
30+
description: ''
31+
branch_tag_screaming:
32+
description: ''
33+
image_latest_artefact:
34+
description: ''
35+
image_latest_tag:
36+
description: ''
37+
image_version_artefact:
38+
description: ''
39+
image_version_tag:
40+
description: ''
41+
short_sha:
42+
description: ''
43+
version_slug:
44+
description: ''
45+
gcp_environment:
46+
description: ''
47+
gcp_project_name:
48+
description: ''
49+
gcp_project_number:
50+
description: ''
51+
gcp_region:
52+
description: ''
53+
gcp_resource_affix:
54+
description: ''
55+
gcp_service:
56+
description: ''
57+
version:
58+
description: ''
59+
60+
runs:
61+
using: 'docker'
62+
# image: 'docker://octue/get-deployment-info:0.1.0'
63+
image: './Dockerfile'
64+
args:
65+
- ${{ inputs.gcp_project_name }}
66+
- ${{ inputs.gcp_project_number }}
67+
- ${{ inputs.gcp_region }}
68+
- ${{ inputs.gcp_resource_affix }}
69+
- ${{ inputs.gcp_environment }}
70+
- ${{ inputs.gcp_service }}

get_info.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Get package version.
2+
VERSION=$(poetry version -s)
3+
echo "version=$VERSION" >> $GITHUB_OUTPUT
4+
5+
# Get GCP variables.
6+
GCP_PROJECT=$1
7+
echo "gcp_project=$GCP_PROJECT" >> $GITHUB_OUTPUT
8+
echo "gcp_project_number=$2" >> $GITHUB_OUTPUT
9+
10+
GCP_REGION=$3
11+
echo "gcp_region=$GCP_REGION" >> $GITHUB_OUTPUT
12+
13+
GCP_RESOURCE_AFFIX=$4
14+
echo "gcp_resource_affix=$GCP_RESOURCE_AFFIX" >> $GITHUB_OUTPUT
15+
echo "gcp_environment=$5" >> $GITHUB_OUTPUT
16+
17+
GCP_SERVICE=$6
18+
echo "gcp_service=$GCP_SERVICE" >> $GITHUB_OUTPUT
19+
20+
# Get slugified branch name, resource names, and docker image tags.
21+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
22+
23+
BRANCH_TAG_KEBAB=$(echo ${GITHUB_REF#refs/heads/} | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z)
24+
echo "branch_tag_kebab=$BRANCH_TAG_KEBAB" >> $GITHUB_OUTPUT
25+
26+
BRANCH_TAG_SCREAMING=$(echo $BRANCH_TAG_KEBAB | tr '[:lower:]' '[:upper:]' | tr - _)
27+
echo "branch_tag_screaming=$BRANCH_TAG_SCREAMING" >> $GITHUB_OUTPUT
28+
29+
if [ "$BRANCH_TAG_KEBAB" = "main" ]; then
30+
TAG_VERSION=$VERSION
31+
else
32+
TAG_VERSION="unreleased"
33+
fi
34+
35+
VERSION_SLUG=$(echo $TAG_VERSION | tr . -)
36+
echo "version_slug=$VERSION_SLUG" >> $GITHUB_OUTPUT
37+
38+
IMAGE_VERSION_TAG="$BRANCH_TAG_KEBAB-$TAG_VERSION"
39+
echo "image_version_tag=$IMAGE_VERSION_TAG" >> $GITHUB_OUTPUT
40+
41+
IMAGE_LATEST_TAG="$BRANCH_TAG_KEBAB-latest"
42+
echo "image_latest_tag=$IMAGE_LATEST_TAG" >> $GITHUB_OUTPUT
43+
44+
# Set image artefact addresses.
45+
echo "image_version_artefact=$GCP_REGION-docker.pkg.dev/$GCP_PROJECT/$GCP_RESOURCE_AFFIX/$GCP_SERVICE:$IMAGE_VERSION_TAG" >> $GITHUB_OUTPUT
46+
echo "image_latest_artefact=$GCP_REGION-docker.pkg.dev/$$GCP_PROJECT/$GCP_RESOURCE_AFFIX/$GCP_SERVICE:$IMAGE_LATEST_TAG" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)