Skip to content

Commit 7b52269

Browse files
integrated ci/cd process to aws staging
1 parent 738c8a3 commit 7b52269

6 files changed

Lines changed: 237 additions & 0 deletions

File tree

.DS_Store

8 KB
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 'Post Deploy Comment'
2+
3+
on:
4+
repository_dispatch:
5+
types: [deploy-complete]
6+
7+
jobs:
8+
post-comment:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: 💬 Post deploy info to PR
12+
uses: actions/github-script@v7
13+
with:
14+
script: |
15+
const prNumber = '${{ github.event.client_payload.pr_number }}';
16+
const deployUrl = '${{ github.event.client_payload.deploy_url }}';
17+
const slotNumber = '${{ github.event.client_payload.slot_number }}';
18+
const appName = '${{ github.event.client_payload.app_name }}';
19+
const namespace = '${{ github.event.client_payload.namespace }}';
20+
21+
const body = `## 🚀 Deploy Complete!
22+
23+
| Property | Value |
24+
|----------|-------|
25+
| **App** | \`${appName}\` |
26+
| **Slot** | \`${slotNumber}\` |
27+
| **URL** | [${deployUrl}](${deployUrl}) |
28+
| **Namespace** | \`${namespace}\` |
29+
30+
*(Environment ready for testing)*`;
31+
32+
await github.rest.issues.createComment({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
issue_number: parseInt(prNumber),
36+
body: body
37+
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: 01 PR Deploy to Staging (Kubernetes)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
deploy_target:
7+
description: 'What to deploy'
8+
required: true
9+
type: choice
10+
options:
11+
- pr
12+
- master
13+
default: pr
14+
pr_number:
15+
description: 'Number of PR to deploy (only digits, e.g., 2889). Required only for PR deploy.'
16+
required: false
17+
type: string
18+
19+
permissions:
20+
id-token: write
21+
contents: read
22+
pull-requests: write
23+
24+
env:
25+
APP_NAME: epp-proxy
26+
ECR_URL: 034362061030.dkr.ecr.eu-north-1.amazonaws.com
27+
AWS_REGION: eu-north-1
28+
EKS_ASSUME_ROLE_ARN: arn:aws:iam::605134427993:role/terraform
29+
30+
jobs:
31+
build-and-deploy:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: ✅ Validate inputs
36+
run: |
37+
if [[ "${{ inputs.deploy_target }}" == "pr" && -z "${{ inputs.pr_number }}" ]]; then
38+
echo "::error::PR number is required when deploy target is 'pr'"
39+
exit 1
40+
fi
41+
42+
- name: ⬇️ Checkout application code
43+
uses: actions/checkout@v4
44+
with:
45+
ref: ${{ inputs.deploy_target == 'master' && 'master' || format('refs/pull/{0}/merge', inputs.pr_number) }}
46+
47+
- name: 🔑 Configure AWS Credentials (for ECR and EKS)
48+
uses: aws-actions/configure-aws-credentials@v4
49+
with:
50+
role-to-assume: ${{ secrets.GH_ACTIONS_DEPLOY_ROLE_ARN }}
51+
aws-region: ${{ env.AWS_REGION }}
52+
53+
- name: 🛠️ Build and Tag Docker image
54+
id: docker_build
55+
run: |
56+
if [[ "${{ inputs.deploy_target }}" == "master" ]]; then
57+
SHORT_SHA=$(git rev-parse --short HEAD)
58+
TAG="master-${SHORT_SHA}"
59+
else
60+
TAG="pr-${{ inputs.pr_number }}"
61+
fi
62+
63+
echo "IMAGE_TAG=$TAG" >> $GITHUB_OUTPUT
64+
65+
docker build --no-cache --platform linux/amd64 -f Dockerfile.staging \
66+
-t ${{ env.APP_NAME }}:${TAG} .
67+
68+
- name: 🔑 ECR Login using AWS CLI
69+
run: |
70+
aws ecr get-login-password --region ${{ env.AWS_REGION }} | \
71+
docker login --username AWS --password-stdin ${{ env.ECR_URL }}
72+
73+
- name: ⬆️ Push Docker image to ECR
74+
run: |
75+
TAG=${{ steps.docker_build.outputs.IMAGE_TAG }}
76+
ECR_IMAGE="${{ env.ECR_URL }}/${{ env.APP_NAME }}:${TAG}"
77+
docker tag ${{ env.APP_NAME }}:${TAG} ${ECR_IMAGE}
78+
docker push ${ECR_IMAGE}
79+
80+
- name: 🔐 Mint GitHub App installation token (for IaC repo)
81+
id: app-token
82+
uses: actions/create-github-app-token@v2
83+
with:
84+
app-id: ${{ vars.GH_APP_ID }}
85+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
86+
owner: internetee
87+
repositories: Ry_AWS_IaC
88+
89+
- name: 🚀 Trigger IaC deploy (repository_dispatch)
90+
uses: peter-evans/repository-dispatch@v3
91+
with:
92+
token: ${{ steps.app-token.outputs.token }}
93+
repository: internetee/Ry_AWS_IaC
94+
event-type: deploy-service-staging
95+
client-payload: |
96+
{
97+
"app_name": "epproxy",
98+
"image_tag": "${{ steps.docker_build.outputs.IMAGE_TAG }}",
99+
"namespace": "epproxy",
100+
"pr_number": "${{ inputs.deploy_target == 'master' && '0' || inputs.pr_number }}",
101+
"source_repo": "internetee/epp_proxy"
102+
}
103+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 02 Manual Destroy Staging
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: 'Number of PR to destroy (only digits, e.g., 2890)'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
destroy-request:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: 🔐 Mint GitHub App token
16+
id: app-token
17+
uses: actions/create-github-app-token@v2
18+
with:
19+
app-id: ${{ vars.GH_APP_ID }}
20+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
21+
owner: internetee
22+
repositories: Ry_AWS_IaC
23+
24+
- name: 🚀 Send Destroy Signal to IaC
25+
uses: peter-evans/repository-dispatch@v3
26+
with:
27+
token: ${{ steps.app-token.outputs.token }}
28+
repository: internetee/Ry_AWS_IaC
29+
event-type: cleanup-service-staging
30+
client-payload: |
31+
{
32+
"app_name": "eppproxy",
33+
"namespace": "${{ github.event.repository.name }}-pr-${{ github.event.inputs.pr_number }}",
34+
"pr_number": "${{ github.event.inputs.pr_number }}"
35+
}

Dockerfile.staging

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM debian:bullseye-slim
2+
3+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4+
COPY ./docker/apt/sources.list /etc/apt/
5+
6+
# Install all dependencies in a single layer to reduce image size
7+
RUN apt-get update && apt-get install -y -qq \
8+
wget \
9+
git \
10+
build-essential \
11+
libncurses5-dev \
12+
automake \
13+
autoconf \
14+
curl \
15+
ca-certificates \
16+
libssl-dev \
17+
libreadline-dev \
18+
libdpkg-perl \
19+
liberror-perl \
20+
libc6 \
21+
libc-dev \
22+
perl \
23+
procps \
24+
inotify-tools \
25+
libssl1.1 \
26+
perl-base \
27+
zlib1g-dev \
28+
# Additional dependencies for Erlang build
29+
libncurses-dev \
30+
libsctp-dev \
31+
# Documentation tools to prevent build failures
32+
xsltproc \
33+
libxml2-utils \
34+
# Dependencies for Ruby 3.2.2
35+
libffi-dev \
36+
libyaml-dev \
37+
&& apt-get clean \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
# Set environment variables for Erlang build
41+
ENV KERL_CONFIGURE_OPTIONS="--disable-debug --without-javac --without-wx --without-odbc --disable-hipe --without-jinterface --without-docs"
42+
ENV KERL_BUILD_DOCS="no"
43+
ENV KERL_DOC_TARGETS=""
44+
ENV KERL_INSTALL_HTMLDOCS="no"
45+
ENV KERL_INSTALL_MANPAGES="no"
46+
47+
RUN git clone https://github.com/asdf-vm/asdf.git --branch v0.6.3 "$HOME"/.asdf && \
48+
echo '. $HOME/.asdf/asdf.sh' >> "$HOME"/.bashrc && \
49+
echo '. $HOME/.asdf/asdf.sh' >> "$HOME"/.profile
50+
51+
ENV PATH="${PATH}:/root/.asdf/shims:/root/.asdf/bin"
52+
53+
RUN mkdir -p /opt/erlang/epp_proxy
54+
WORKDIR /opt/erlang/epp_proxy
55+
56+
COPY .tool-versions ./
57+
RUN asdf plugin-add erlang
58+
RUN . $HOME/.asdf/asdf.sh && asdf install
59+
RUN asdf global erlang $(grep erlang .tool-versions | cut -d' ' -f2)
60+
RUN asdf plugin-add ruby
61+
RUN asdf plugin-add rebar
62+
RUN asdf install

apps/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)