Install app as a service. Update application upon deployment without destroing it. Added elastic ip
Some checks failed
AWS Deploy on Push / build (push) Failing after 4m0s
Some checks failed
AWS Deploy on Push / build (push) Failing after 4m0s
This commit is contained in:
@@ -13,28 +13,39 @@ jobs:
|
|||||||
- run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
- run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||||
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
|
- run: echo "The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Python 3.12
|
- name: Set up Python 3.12
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: "3.12"
|
python-version: "3.12"
|
||||||
|
|
||||||
- name: Set up Node
|
- name: Set up Node
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: "22.15"
|
node-version: "22.15"
|
||||||
|
|
||||||
- name: Install Python dependencies and CDK
|
- name: Install Python dependencies and CDK
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install aws-cdk-lib constructs
|
pip install aws-cdk-lib constructs
|
||||||
npm install -g aws-cdk
|
npm install -g aws-cdk
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@master
|
uses: aws-actions/configure-aws-credentials@master
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
|
||||||
aws-region: "us-east-2"
|
aws-region: "us-east-2"
|
||||||
- name: Destroy existing stack
|
|
||||||
run: cdk destroy --app="python3 ${PWD}/app.py" --force
|
|
||||||
- name: Deploy to AWS
|
- name: Deploy to AWS
|
||||||
run: cdk deploy --app="python3 ${PWD}/app.py" --require-approval=never
|
run: cdk deploy --app="python3 ${PWD}/app.py" --require-approval=never
|
||||||
|
|
||||||
|
- name: Update application on instance
|
||||||
|
run: |
|
||||||
|
INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=IptvUpdater/IptvUpdaterInstance" --query "Reservations[*].Instances[*].InstanceId" --output text)
|
||||||
|
aws ssm send-command \
|
||||||
|
--instance-ids "$INSTANCE_ID" \
|
||||||
|
--document-name "AWS-RunShellScript" \
|
||||||
|
--parameters 'commands=["cd /home/ec2-user/iptv-updater-aws && git pull && pip3 install -r requirements.txt && systemctl restart iptv-updater"]'
|
||||||
|
|
||||||
- run: echo "This job's status is ${{ job.status }}."
|
- run: echo "This job's status is ${{ job.status }}."
|
||||||
@@ -97,8 +97,15 @@ class IptvUpdaterStack(Stack):
|
|||||||
user_data=userdata,
|
user_data=userdata,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Create Elastic IP
|
||||||
|
eip = ec2.CfnEIP(
|
||||||
|
self, "IptvUpdaterEIP",
|
||||||
|
domain="vpc",
|
||||||
|
instance_id=instance.instance_id
|
||||||
|
)
|
||||||
|
|
||||||
# Output the public DNS name
|
# Output the public DNS name
|
||||||
CfnOutput(
|
CfnOutput(
|
||||||
self, "InstancePublicDNS",
|
self, "InstancePublicDNS",
|
||||||
value=instance.instance_public_dns_name
|
value=eip.attr_public_ip
|
||||||
)
|
)
|
||||||
@@ -14,8 +14,26 @@ cd iptv-updater-aws
|
|||||||
|
|
||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
# Create systemd service file
|
||||||
|
cat << 'EOF' > /etc/systemd/system/iptv-updater.service
|
||||||
|
[Unit]
|
||||||
|
Description=IPTV Updater Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=ec2-user
|
||||||
|
WorkingDirectory=/home/ec2-user/iptv-updater-aws
|
||||||
|
ExecStart=/usr/local/bin/uvicorn app.main:app --host 127.0.0.1 --port 8000
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
# Create nginx config
|
# Create nginx config
|
||||||
echo 'server {
|
cat << 'EOF' > /etc/nginx/conf.d/iptvUpdater.conf
|
||||||
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name $HOSTNAME;
|
server_name $HOSTNAME;
|
||||||
location / {
|
location / {
|
||||||
@@ -25,11 +43,11 @@ echo 'server {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
}' > /etc/nginx/conf.d/iptvUpdater.conf
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
# Start nginx service
|
# Start nginx service
|
||||||
systemctl enable nginx
|
systemctl enable nginx
|
||||||
systemctl start nginx
|
systemctl start nginx
|
||||||
|
systemctl enable iptv-updater
|
||||||
# Start IptvUpdater on port 8000
|
systemctl start iptv-updater
|
||||||
nohup uvicorn app.main:app --host 127.0.0.1 --port 8000 </dev/null &>/dev/null &
|
|
||||||
Reference in New Issue
Block a user