fixed issue in github action #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🚀 Deployment | |
# Only trigger, when the build workflow succeeded | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_LIGHTSAIL_SERVICE_NAME: ${{ secrets.AWS_SERVICE_NAME }} | |
concurrency: | |
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' | |
cancel-in-progress: true | |
jobs: | |
buildnginx: | |
name: 🌎 building nginx webserver | |
runs-on: ubuntu-latest | |
steps: | |
- name: 🗂 Getting code from Github | |
uses: actions/checkout@v2 | |
- name: ⚙️ Updating to the latest versions | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq unzip | |
- name: 🏢 Install Amazon Client | |
run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip awscliv2.zip | |
sudo ./aws/install || true | |
aws --version | |
curl "https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl" -o "lightsailctl" | |
sudo mv "lightsailctl" "/usr/local/bin/lightsailctl" | |
sudo chmod +x /usr/local/bin/lightsailctl | |
- name: 🤐 Log in to AWS Lightsail with Secrets | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: ${{ env.AWS_REGION }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: 🐳 Create a Docker Container for NGINX | |
run: docker build -t nginx:latest -f ./AWS/nginx/Dockerfile . | |
- name: 📬 Upload NGINX image to AWS container register | |
run: | | |
service_name=${{ env.AWS_LIGHTSAIL_SERVICE_NAME }} | |
aws lightsail push-container-image \ | |
--region ${{ env.AWS_REGION }} \ | |
--service-name ${service_name} \ | |
--label nginx \ | |
--image nginx:latest | |
- name: =========== All done. Cleaning up ♻️ =========== | |
run: ls | |
builddjango: | |
name: 🚨 Deploying | |
runs-on: ubuntu-latest | |
steps: | |
- name: 🗂 Getting code from Github | |
uses: actions/checkout@v2 | |
- name: ⚙️ Updating to the latest versions | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq unzip | |
- name: 🏢 Install Amazon Client | |
run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip awscliv2.zip | |
sudo ./aws/install || true | |
aws --version | |
curl "https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl" -o "lightsailctl" | |
sudo mv "lightsailctl" "/usr/local/bin/lightsailctl" | |
sudo chmod +x /usr/local/bin/lightsailctl | |
- name: 🤐 Log in to AWS Lightsail with Secrets | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: ${{ secrets.AWS_REGION }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: 🤐 Make envfile | |
uses: SpicyPizza/create-envfile@v1.3 | |
with: | |
envkey_DB_USER: ${{ secrets.DB_USER }} | |
envkey_DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
envkey_DB_HOST: ${{ secrets.DB_HOST }} | |
envkey_DB_NAME: ${{ secrets.DB_NAME }} | |
envkey_DB_PORT: ${{ secrets.DB_PORT }} | |
envkey_S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} | |
envkey_S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }} | |
envkey_S3_AWS_STORAGE_BUCKET_NAME: ${{ secrets.S3_AWS_STORAGE_BUCKET_NAME }} | |
envkey_DEBUG: false | |
directory: core | |
file_name: .env | |
fail_on_empty: false | |
- name: Installing dependancies | |
run: | | |
sudo pip3 install --upgrade pip | |
sudo pip3 install -r requirements.txt | |
- name: 🐳 Create a Docker Container for DJANGO | |
run: docker build -t django:latest . | |
- name: 📬 Upload Backend image to AWS container register | |
run: | | |
service_name=${{ env.AWS_LIGHTSAIL_SERVICE_NAME }} | |
aws lightsail push-container-image \ | |
--region ${{ env.AWS_REGION }} \ | |
--service-name ${AWS_LIGHTSAIL_SERVICE_NAME} \ | |
--label django \ | |
--image django:latest | |
- name: 🚀 Launching the Containers | |
run: | | |
aws lightsail create-container-service-deployment --service-name ${{ env.AWS_LIGHTSAIL_SERVICE_NAME }} \ | |
--containers file://AWS/deploymentconfig.json \ | |
--public-endpoint file://AWS/publicendpoint.json | |