Skip to content

Commit d9603f2

Browse files
committed
feat: add Docker Compose actions
1 parent bcf774d commit d9603f2

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

.github/workflows/dc_edit.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: 'DC: Edit'
2+
3+
on:
4+
workflow_call:
5+
6+
# Special permissions required for OIDC authentication
7+
permissions:
8+
id-token: write
9+
contents: read
10+
actions: read
11+
12+
env:
13+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
14+
15+
jobs:
16+
dc-edit:
17+
name: 'Docker Compose: Edit Service'
18+
runs-on: [self-hosted, "${{ github.event_name == 'release' && 'prod' || github.event.pull_request.base.ref }}"]
19+
environment: ${{ github.event_name == 'release' && 'prod' || github.event.pull_request.base.ref }}
20+
env:
21+
ENVIRONMENT_NAME: ${{ github.event_name == 'release' && 'prod' || github.event.pull_request.base.ref }}
22+
DEPLOYMENT_REPO_NAME: ${{ vars.DEPLOYMENT_REPO_NAME }}
23+
CONTAINER_REGISTRY: "${{ vars.CONTAINER_REGISTRY }}"
24+
IMAGE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'dev' }}
25+
steps:
26+
# Checkout the repository to the GitHub Actions runner
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
with:
30+
token: ${{ secrets.GH_TOKEN }}
31+
repository: ${{ github.repository_owner }}/${{ env.DEPLOYMENT_REPO_NAME }}
32+
fetch-depth: 0
33+
34+
- name: GitHub Configuration
35+
run: git config --global url."https://oauth2:${{ secrets.GH_TOKEN }}@github.com".insteadOf https://github.com
36+
37+
- name: Clone cicd-deployment-scripts
38+
run: git clone https://github.com/code-kern-ai/cicd-deployment-scripts.git
39+
40+
- name: Perform Edit/Git Operations
41+
shell: bash
42+
run: |
43+
AUTOMATED_RELEASE_BRANCH="automated-release-${{ github.event_name == 'release' && 'prod' || 'dev' }}"
44+
45+
git checkout $AUTOMATED_RELEASE_BRANCH || git checkout -b $AUTOMATED_RELEASE_BRANCH
46+
git push origin $AUTOMATED_RELEASE_BRANCH && git pull origin $AUTOMATED_RELEASE_BRANCH
47+
48+
bash cicd-deployment-scripts/dc/edit.sh \
49+
-e ${{ env.ENVIRONMENT_NAME }} \
50+
-r ${{ env.CONTAINER_REGISTRY }} \
51+
-s ${{ github.event.repository.name }} \
52+
-t ${{ env.IMAGE_TAG }}
53+
54+
git config --global user.email "[email protected]"
55+
git config --global user.name "GitHub Actions"
56+
57+
git add .env.${{ env.ENVIRONMENT_NAME }}
58+
git commit -m "ci(${{ github.event.repository.name }}): ${{ env.IMAGE_TAG }}" || true
59+
git push origin $AUTOMATED_RELEASE_BRANCH
60+
61+
PR_TITLE="ci: $AUTOMATED_RELEASE_BRANCH"
62+
if [ ${{ github.event_name }} == 'release' ]; then
63+
PR_TITLE="ci(release): $AUTOMATED_RELEASE_BRANCH"
64+
fi
65+
66+
bash cicd-deployment-scripts/gh/pr_create.sh \
67+
-b dev \
68+
-h "$AUTOMATED_RELEASE_BRANCH" \
69+
-t "$PR_TITLE" \
70+
-o "${{ github.repository_owner }}" \
71+
-r "${{ github.event.repository.name }}" \
72+
-n "${{ github.event.pull_request.number }}" \
73+
-k "${{ env.DEPLOYMENT_REPO_NAME }}" \

.github/workflows/dc_release.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'DC: Release'
2+
3+
on:
4+
workflow_call:
5+
6+
# Special permissions required for OIDC authentication
7+
permissions:
8+
id-token: write
9+
contents: read
10+
actions: read
11+
12+
jobs:
13+
call-gh-validate-release:
14+
if: github.event_name == 'release'
15+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/gh_validate_release.yml@dev
16+
secrets: inherit
17+
18+
# call-az-acr-release:
19+
# needs: [call-gh-validate-release]
20+
# if: always() && !failure()
21+
# uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/az_acr_release.yml@dev
22+
# secrets: inherit
23+
24+
call-dc-edit:
25+
needs: [call-gh-validate-release] # [call-az-acr-release]
26+
if: always() && !failure()
27+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/dc_edit.yml@dev
28+
secrets: inherit
29+
30+
call-gh-release:
31+
# needs: [call-k8-deploy]
32+
needs: [call-dc-edit]
33+
if: always() && github.event_name == 'release'
34+
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/gh_release.yml@dev
35+
secrets: inherit
36+
with:
37+
deployment_status: "success"
38+
39+
gh-delete-branch:
40+
name: 'GitHub: Delete Branch'
41+
runs-on: ubuntu-latest
42+
needs: [call-dc-edit]
43+
if: github.event_name == 'pull_request' && github.event.pull_request.merged && !failure() && !cancelled()
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
with:
48+
token: ${{ secrets.GH_TOKEN }}
49+
50+
- name: Delete Branch
51+
shell: bash
52+
run: git push origin --delete ${{ github.head_ref }}

dc/edit.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# !/bin/bash
2+
set -e
3+
4+
ENVIRONMENT_NAME=""
5+
CONTAINER_REGISTRY=""
6+
DOCKER_COMPOSE_SERVICE=""
7+
IMAGE_TAG=""
8+
9+
while getopts e:r:s:t: flag
10+
do
11+
case "${flag}" in
12+
e) ENVIRONMENT_NAME=${OPTARG};;
13+
r) CONTAINER_REGISTRY=${OPTARG};;
14+
s) DOCKER_COMPOSE_SERVICE=${OPTARG};;
15+
t) IMAGE_TAG=${OPTARG};;
16+
esac
17+
done
18+
19+
APP_NAME=$(echo "${DOCKER_COMPOSE_SERVICE//-/_}" | tr '[:lower:]' '[:upper:]')
20+
21+
line=$(grep "${APP_NAME}=" .env.${ENVIRONMENT_NAME})
22+
23+
APP_EXISTING_TAG=$(echo $line | sed "s|$APP_NAME=||g" | cut -d ':' -f 2)
24+
APP_EXISTING_IMAGE="${CONTAINER_REGISTRY}/${DOCKER_COMPOSE_SERVICE}:${APP_EXISTING_TAG}"
25+
APP_NEW_IMAGE="${CONTAINER_REGISTRY}/${DOCKER_COMPOSE_SERVICE}:${IMAGE_TAG}"
26+
27+
echo "$(sed 's|'${APP_EXISTING_IMAGE}'|'${APP_NEW_IMAGE}'|g' .env.${ENVIRONMENT_NAME})" > .env.${ENVIRONMENT_NAME}
28+
echo "::notice::.env.${ENVIRONMENT_NAME} updated with new image: ${APP_NEW_IMAGE}"

0 commit comments

Comments
 (0)