How to add a gitignore folder to github actions? - django

I have a Django Project and created a dev branch. In my .gitignore file I have the "media" folder. My project looks like this:
- Django Project/
- app1/
- app2/
- media/
- profile_pics/
- default.jpg
- .gitignore
In my gitignore I added media.
I've been trying to add github actions, so I created this ci.yml
name: Testing
on: push
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout#v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python#v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test
When I push the repo I received this message from Github Actions:
FileNotFoundError: [Errno 2] No such file or directory: '****/media/default.jpg'
What is the best way to deal with this?
I could use git add media -f but I do not know if then this file would be in my repo and when I merge it with main and deploy it I would have that folder and overwrites the media in deployment.

Remove your media directory from .gitignore so that it is tracked by Git. It sounds like you need that directory for your project to successfully build.
If you're concerned about large artifacts, then see also git lfs (large file storage) supported by GitHub. Either way, you need to fix your .gitignore.

Related

How to restart Nginx server with Github Action yaml file

I am working on a Django project, I am new in Github Action,
I had set up Github action file
name: Django CI
on:
push:
branches: [ master ]
jobs:
build:
runs-on: self-hosted
steps:
- uses: actions/checkout#v3
- name: Install Dependencies
run: |
virtualenv -p python3 env
. env/bin/activate
pip3 install -r requirements.txt
My file get uploaded but issues is that I had to restart the Nginx server,
How I can Restart Nginx server

How to run two commands on Github Actions instance one after another?

So question seems easy but let me start with this, ";" "&" does not work.
The two commands to be ran on Github actions instance in CI/CD pipeline :
python3 manage.py runserver
python3 abc.py
After putting the command in the yaml file, only the first command runs and then the workflow is stuck there only and does not executes the second command.
I have tried putting in two separate blocks in workflow yaml file but no luck.
There are two to run commands one after another on Github Actions.
On the same step:
steps:
- name: Run both python files
run: |
python manage.py runserver
python abc.py
On different steps (that will run in sequence):
steps:
- name: Run first python file
run: python manage.py runserver
- name: Run second python file
run: python abc.py
Also, you don't need to inform python3, just python is enough, as you will use the setup/python action informing the version first.
Therefore, your whole workflow would probably look like this:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository content
uses: actions/checkout#v2.3.4
- name: Setup Python Version
uses: actions/setup-python#v2
with:
python-version: 3.8
- name: Install Python dependencies
run: python -m pip install --upgrade pip [...] # if necessary
- name: Execute Python scripts
run: |
python manage.py runserver
python abc.py

Expo Web Build in Vercel - Command "npx expo-cli build:web" exited with 1

I want to build and deploy my expo app in vercel. I know that I can build it locally (expo build:web), cd into the build folder and run vercel, but I would like it to be done automatically with source control integration.
So I have connected my github repository, npm install seems to be working ok. The problem is with the build command. I tried expo build:web but this failed because the expo cli is not installed in vercel, so I tried npx expo-cli build:web and got the folloowing output: Command "npx expo-cli build:web" exited with 1.
Error: Could not find MIME for Buffer <null>
at /vercel/.npm/_npx/727/lib/node_modules/expo-cli/node_modules/xdl/src/Webpack.ts:294:23
at finalCallback (/vercel/.npm/_npx/727/lib/node_modules/expo-cli/node_modules/webpack/lib/Compiler.js:257:39)
Does anyone know how I can run expo build:web in vercel? Many thanks
From my perspective, I think you need to use something like GitHub actions for this task.
I wrote a post on How I automated the releases with the expo-cli and I think we need to follow the same logic.
// .github/workflows/staging.yml
name: Expo Publish on Staging
on:
push:
branches:
- develop
jobs:
publish:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-node#v1
with:
node-version: 12.x
- uses: expo/expo-github-action#v5
with:
expo-version: 3.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
- run: yarn
- run: expo build:web <------- not sure if it works tho
- run: <------- here we need a way to upload to vercel
I am in the same situation as you —trying to automate the react-native-web to vercel release.
I had the same issue, but found a solution. expo build:web creates a production ready static bundle in the web-build/ directory, which Vercel can deploy. Thus, to deploy the Expo Web-app to Vercel, one can first have a GHA-step that runs expo build:web and then deploy the bundle it produces to Vercel.
Note that one either has to specify the path to the web-build directory as the root-directory in Vercel (which is done in the code below) or has to set the working-directory to the web-build-path in the Vercel step in the code.
Full Github Actions code for job:
deploy-web-staging:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup .npmrc and use node 14.15.1
uses: actions/setup-node#v1
with:
node-version: 14.15.1
- name: Expo Web
uses: expo/expo-github-action#v5
with:
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Build Expo Web
working-directory: ./packages/app
run: expo build:web
- name: Vercel Deploy
uses: amondnet/vercel-action#v20.0.0
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: VERCEL_ORG_ID
vercel-project-id: VERCEL_PROJECT_ID
scope: TEAM

I'm trying to add env var to django secret_key on github action but showing error

name: MoneyTracker Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up python 3.7
uses: actions/setup-python#v2
with:
python-version: 3.7
- name: Install dependency
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
flake8
- name: Coverage report
env:
secret_key: ${{secrets.SECRET_KEY}}
debug: ${{secrets.DEBUG}}
db: ${{secrets.DB}}
run: |
pip install coverage
coverage run MoneyTracker/manage.py test
coverage report
- name: Django testing
run: |
python3 MoneyTracker/manage.py test MoneyTracker
Project link is in here.
How should I add secret key to my project on GitHub action?
Environment variables are case-sensitive. Commands run in actions or steps can create, read, and modify environment variables. To set custom environment variables, you need to specify the variables in the workflow file. You can define environment variables for a step, job, or entire workflow using the jobs.
1. (Recommended way for Secrets) The preferred and secure way is to add the Secret env variables in your GitHub repo settings (See this [Link] for more info. Then you can use those variables with the below syntax in your actions/django.yml file.
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
See below image or this Link
Add Secrets in Github Repo
1. (Not recommended for Secrets) You can set the env variables using the below syntax, or you can follow Official Docs Here. But if your repo is public then this method will still expose your SECRET_KEY so I wouldn't recommend this for secrets. However, this method can be used if you want to set env variables like PATH.
env:
SECRET_KEY: your_django_secret_key

CircleCi 2.0: aws command not found

I try to migrate circleci from v1.0 to v2.0.
First I can't install awscli but finally can install it with the code below but got another error that cannot found aws command.
version: 2
jobs:
build:
docker:
- image: circleci/node:8.9.1
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
deploy:
docker:
- image: circleci/node:8.9.1
steps:
- checkout
- run:
name: Install yarn
command: yarn install
- run:
name: Install awscli
command: |
sudo apt-get install python-pip python-dev
pip install 'pyyaml<4,>=3.10' awscli --upgrade --user
- run:
name: AWS S3
command: aws s3 sync build s3://<URL> --delete
workflows:
version: 2
build-and-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master
It show "aws: command not found". I'm not sure that I do something wrong or not but I want to know what's the problem and how to solve it. Thanks.
I would rework your config. Each job should have a focus/point. For deployment for example, you don't need NodeJS, you need the AWS CLI so use an image for that.
version: 2
jobs:
build:
docker:
- image: circleci/node:8.9.1
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
- persist_to_workspace:
root: /home/circleci
paths: project
deploy:
docker:
- image: cibuilds/aws:1.16.1
steps:
- checkout
- attach_workspace:
at: /home/circleci
- run:
name: AWS S3
command: aws s3 sync build s3://<URL> --delete
workflows:
version: 2
build-and-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: master
Try with the following step (taken from their v2 docs);
steps:
- run:
name: Install PIP
command: sudo apt-get install python-pip python-dev
- run:
name: Install awscli
command: sudo pip install awscli
- run:
name: Deploy to S3
command: aws s3 sync build s3://<URL> --delete
This method for installing awscli seems to work fine on a variety of systems. Tested on circleci/openjdk:8-jdk, requires no additional installation.
Edit
Seems that the node image lacks the installation of libpython-dev.
##################
# Install AWS CLI
##################
# For node images on Circle, install libpython-dev
sudo apt-get install -y libpython-dev
# Download awscli bundle
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
# Unzip the downloaded bundle
unzip awscli-bundle.zip
# Run the install script and install to ~/bin/aws directory
./awscli-bundle/install -b ~/bin/aws
After that, to run awscli commands, specify the full path to the aws executable, for example:
~/bin/aws s3 ls
Resources
Helpful thread GitHub
Example GitHub repository with Circle config on node:8.9.1
The CircleCI builds