Skip to content

Commit b6b7fa1

Browse files
author
Emil Matyjaszewski
committed
Add SDLC workflow
1 parent 59919f6 commit b6b7fa1

File tree

4 files changed

+178
-70
lines changed

4 files changed

+178
-70
lines changed

.github/workflows/sdlc-push.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: SDLC - Branch push
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
8+
jobs:
9+
prepare-docker:
10+
name: "Prepare Docker image tag"
11+
runs-on: ubuntu-latest
12+
outputs:
13+
docker_image_tag: ${{ steps.sanitize-branch.outputs.docker_image_tag }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Get current branch name
19+
id: get-branch
20+
run: |
21+
if [[ "${GITHUB_REF}" == refs/pull/*/merge ]]; then
22+
BRANCH_NAME="${GITHUB_HEAD_REF}"
23+
else
24+
BRANCH_NAME="${GITHUB_REF_NAME}"
25+
fi
26+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
27+
28+
- name: Sanitize branch name for Docker
29+
id: sanitize-branch
30+
run: |
31+
SAFE_BRANCH=$(echo "${{ steps.get-branch.outputs.branch_name }}" | tr '[:upper:]' '[:lower:]' | sed 's#[^a-z0-9_.-]#-#g')
32+
echo "docker_image_tag=$SAFE_BRANCH" >> $GITHUB_OUTPUT
33+
34+
build-push:
35+
name: "Build & push image"
36+
runs-on: ubuntu-latest
37+
needs: [prepare-docker]
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Log in to Docker Hub
46+
uses: docker/login-action@v3
47+
with:
48+
username: ${{ secrets.DOCKERHUB_USERNAME }}
49+
password: ${{ secrets.DOCKERHUB_TOKEN }}
50+
51+
- name: Build and push image
52+
run: |
53+
IMAGE_TAG="${{ needs.prepare-docker.outputs.docker_image_tag }}"
54+
docker buildx create --use
55+
docker buildx build \
56+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-develop \
57+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG \
58+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG \
59+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:$IMAGE_TAG \
60+
-f ./docker/Dockerfile \
61+
--push \
62+
./
63+
64+
deploy:
65+
name: "Trigger deployment"
66+
if: github.ref == 'refs/heads/develop'
67+
needs: [build-push]
68+
uses: ./.github/workflows/trigger-azure-pipeline.yml
69+
with:
70+
azure-organization: ${{ vars.AZURE_ORGANIZATION }}
71+
azure-project: ${{ vars.AZURE_PROJECT }}
72+
azure-pipeline-id: ${{ vars.AZURE_PIPELINE_ID_DEVELOP }}
73+
image-tag: "develop"
74+
secrets:
75+
azure-pat: ${{ secrets.AZURE_PAT }}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: SDLC - Version create
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+*' # Allows semver format and any suffix (i.e. 'rc1')
7+
8+
jobs:
9+
prepare-version:
10+
name: "Prepare version number"
11+
runs-on: ubuntu-latest
12+
outputs:
13+
version: ${{ steps.version.outputs.version }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Extract tag
19+
id: version
20+
run: |
21+
TAG_NAME="${GITHUB_REF#refs/tags/}"
22+
echo "Extracted tag: $TAG_NAME"
23+
echo "version=$TAG_NAME" >> $GITHUB_OUTPUT
24+
25+
build-push:
26+
name: "Build & push image"
27+
runs-on: ubuntu-latest
28+
needs: [prepare-version]
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Log in to Docker Hub
34+
uses: docker/login-action@v3
35+
with:
36+
username: ${{ secrets.DOCKERHUB_USERNAME }}
37+
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
39+
- name: Build and push versioned image
40+
run: |
41+
IMAGE_TAG="${{ needs.prepare-version.outputs.version }}"
42+
docker buildx create --use
43+
docker buildx build \
44+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-develop \
45+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG \
46+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:cache-$IMAGE_TAG \
47+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/${{ vars.DOCKERHUB_REPOSITORY }}:$IMAGE_TAG \
48+
-f ./docker/Dockerfile \
49+
--push \
50+
./

.github/workflows/test.yml

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -159,73 +159,3 @@ jobs:
159159
token: ${{ secrets.CODECOV_TOKEN }}
160160
verbose: false
161161
name: codecov-${{env.GITHUB_REF_NAME}}
162-
163-
release:
164-
needs: [ test ]
165-
runs-on: ubuntu-latest
166-
services:
167-
redis1:
168-
image: redis:7.4.0
169-
ports:
170-
- 5379:6379
171-
db1:
172-
image: postgres:14
173-
env:
174-
POSTGRES_HOST: db1
175-
POSTGRES_DATABASE: country_workspace
176-
POSTGRES_PASSWORD: postgres
177-
POSTGRES_USERNAME: postgres
178-
ports:
179-
- 4432:5432
180-
options: >-
181-
--health-cmd pg_isready
182-
--health-interval 10s
183-
--health-timeout 5s
184-
--health-retries 5
185-
env:
186-
DOCKER_DEFAULT_PLATFORM: linux/amd64
187-
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
188-
DATABASE_URL: postgres://postgres:postgres@localhost:4432/country_workspace
189-
CELERY_BROKER_URL: redis://localhost:5379/1
190-
CACHE_URL: redis://localhost:5379/2
191-
DOCKER_BUILDKIT: 1
192-
steps:
193-
- name: Checkout code
194-
uses: actions/checkout@v4
195-
- name: DockerHub login
196-
uses: docker/login-action@v3
197-
with:
198-
username: ${{ secrets.DOCKERHUB_USERNAME }}
199-
password: ${{ secrets.DOCKERHUB_TOKEN }}
200-
- name: Build Distro
201-
run: |
202-
docker build \
203-
--target dist \
204-
--cache-from "type=gha" \
205-
--cache-to "type=gha,mode=max" \
206-
--build-arg "GIT_SHA=${{needs.test.outputs.commit}}" \
207-
--build-arg "BUILD_DATE=${{needs.test.outputs.build_date}}" \
208-
--build-arg "BRANCH=${{needs.test.outputs.branch}}" \
209-
-t ${{needs.test.outputs.image}} \
210-
-f docker/Dockerfile .
211-
#
212-
# - name: Docker Integrity Check
213-
# run: |
214-
# docker run --rm \
215-
# --network host \
216-
# -e DATABASE_URL=${DATABASE_URL} \
217-
# -e CELERY_BROKER_URL=${CELERY_BROKER_URL} \
218-
# -e CACHE_URL=${CACHE_URL} \
219-
# -e SECRET_KEY=super-secret-key-just-for-testing \
220-
# -e HOPE_API_URL="https://dev-hope.unitst.org/api/rest/" \
221-
# -e HOPE_API_TOKEN=${{ secrets.HOPE_API_TOKEN }} \
222-
# -e AURORA_API_URL="https://uni-hope-ukr-sr-dev.unitst.org/api/" \
223-
# -e AURORA_API_TOKEN=${{ secrets.AURORA_API_TOKEN }} \
224-
# -t ${{needs.test.outputs.image}} \
225-
# django-admin upgrade
226-
227-
- name: Publish images
228-
run: |
229-
docker push ${{needs.test.outputs.image}}
230-
docker inspect ${{needs.test.outputs.image}} | jq -r '.[0].Config.Labels'
231-
echo "::notice::✅ Image ${{needs.test.outputs.image}} built and pushed"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Trigger pipeline in Azure Pipelines
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
azure-organization:
7+
required: true
8+
type: string
9+
azure-project:
10+
required: true
11+
type: string
12+
azure-pipeline-id:
13+
required: true
14+
type: string
15+
image-tag:
16+
required: true
17+
type: string
18+
secrets:
19+
azure-pat:
20+
required: true
21+
22+
jobs:
23+
deploy:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Trigger deploy
30+
run: |
31+
pipelineId=${{ inputs.azure-pipeline-id }}
32+
33+
IFS=',' read -ra pipelines <<< "$pipelineId"
34+
for pipeline in "${pipelines[@]}"; do
35+
jsonBody='{"variables": {"sha": {"isSecret": false, "value": "${{ github.sha }}"}, "tag": {"isSecret": false, "value": "${{ inputs.image-tag }}"}}}'
36+
contentLength=$(echo -n $jsonBody | wc -c)
37+
organization=${{ inputs.azure-organization }}
38+
project=${{ inputs.azure-project }}
39+
40+
echo Triggering deploy for pipeline $pipeline
41+
echo JSON body: $jsonBody
42+
43+
curl -f -v -L \
44+
-u ":${{ secrets.azure-pat }}" \
45+
-H "Content-Type: application/json" \
46+
-H "Content-Length: $contentLength" \
47+
-d "$jsonBody" \
48+
https://dev.azure.com/$organization/$project/_apis/pipelines/$pipeline/runs?api-version=7.1-preview.1
49+
if [ $? -ne 0 ]; then
50+
echo "Failed to trigger deploy for pipeline $pipeline"
51+
exit 1
52+
fi
53+
done

0 commit comments

Comments
 (0)