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
Related
EDITED
I am learning CICD and Docker. So far I have managed to successfully create a docker image using the code below:
Dockerfile
# Docker Operating System
FROM python:3-slim-buster
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
#App folder on Slim OS
WORKDIR /app
# Install pip requirements
COPY requirements.txt requirements.txt
RUN python -m pip install --upgrade pip pip install -r requirements.txt
#Copy Files to App folder
COPY . /app
docker-compose.yml
version: '3.4'
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- 8000:8000
My code is on BitBucket and I have a pipeline file as follows:
bitbucket-pipelines.yml
image: atlassian/default-image:2
pipelines:
branches:
master:
- step:
name:
Build And Publish To Azure
services:
- docker
script:
- docker login -u $AZURE_USER -p $AZURE_PASS xxx.azurecr.io
- docker build -t xxx.azurecr.io .
- docker push xxx.azurecr.io
With xxx being the Container registry on Azure. When the pipeline job runs I am getting denied: requested access to the resource is denied error on BitBucket.
What did I not do correctly?
Thanks.
The Edit
Changes in docker-compose.yml and bitbucket-pipeline.yml
docker-compose.yml
version: '3.4'
services:
web:
build: .
image: xx.azurecr.io/myticket
container_name: xx
command: python manage.py runserver 0.0.0.0:80
ports:
- 80:80
bitbucket-pipelines.yml
image: atlassian/default-image:2
pipelines:
branches:
master:
- step:
name:
Build And Publish To Azure
services:
- docker
script:
- docker login -u $AZURE_USER -p $AZURE_PASS xx.azurecr.io
- docker build -t xx.azurecr.io/xx .
- docker push xx.azurecr.io/xx
You didnt specify CMD or ENTRYPOINT in your dockerfile.
There are stages when building a dockerfile
Firstly you call an image, then you package your requirements etc.. those are stages that are being executed while the container is building. you are missing the last stage that executes a command inside the container when its already up.
Both ENTRYPOINT and CMD are essential for building and running Dockerfiles.
for it to work you must add a CMD or ENTRYPOINT at the bottom of your dockerfile..
Change your files accordingly and try again.
Dockerfile
# Docker Operating System
FROM python:3-slim-buster
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
#App folder on Slim OS
WORKDIR /app
# Install pip requirements
COPY requirements.txt requirements.txt
RUN python -m pip install --upgrade pip pip install -r requirements.txt
#Copy Files to App folder
COPY . /app
# Execute commands inside the container
CMD manage.py runserver 0.0.0.0:8000
Check you are able to build and run the image by going to its directory and running
docker build -t app .
docker run -d -p 80:80 app
docker ps
See if your container is running.
Next
Update the image property in the docker-compose file.
Prefix the image name with the login server name of your Azure container registry, .azurecr.io. For example, if your registry is named myregistry, the login server name is myregistry.azurecr.io (all lowercase), and the image property is then myregistry.azurecr.io/azure-vote-front.
Change the ports mapping to 80:80. Save the file.
The updated file should look similar to the following:
docker-compose.yml
Copy
version: '3'
services:
foo:
build: .
image: foo.azurecr.io/atlassian/default-image:2
container_name: foo
ports:
- "80:80"
By making these substitutions, the image you build is tagged for your Azure container registry, and the image can be pulled to run in Azure Container Instances.
More in documentation
I'm trying build deploy a app in GCP Cloud run using GCP Cloud Build.
I already build, push and deploy the service using Dockerfile, but i need use the Dockerfile of the project. My dockerfile run in Docker desktop perfectly, but i am not finding documentation for docker-compose using GCP Artifact registry.
My dockerfile:
FROM python:3.10.5-slim-bullseye
#docker build -t cloud_app .
#docker image ls
#docker run -p 81:81 cloud_app
RUN mkdir wd
WORKDIR /wd
RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6 -y
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY ./ ./
CMD python3 main.py
My docker-compose:
version: "3.3"
services:
web:
build:
context: ./destripa_frame/
dockerfile: ./Docker_files/Dockerfile
image: bank_anon_web_dev_build
restart: always
expose:
- 8881
- 80
- 2222
- 22
ports:
- "2222:2222"
- "80:80"
environment:
- TZ=America/Chicago
My cloud-build configuration:
steps:
- name: 'docker/compose:1.28.2'
args: ['up', '--build', '-f', './cloud_run/docker-compose.devapp.yml', '-d']
- name: 'docker/compose:1.28.2'
args: ['-f', './cloud_run/docker-compose.devapp.yml', 'up', 'docker-build']
images: ['us-central1-docker.pkg.dev/${PROJECT_ID}/app-destripador/job_app:$COMMIT_SHA']
The cloud build commit execution succeed:
Cloud build execution
¿How can modify the cloud build for deploy the Docker-compose in Artifact registry?
EDIT: Find the correct method to push the image in artifact registry using cloudbuild and Docker-compose.
Modify my cloud-build.yml configuration for build the image and then rename the Docker-compose image to the Artifact registry image.
Cloud build automatically push the image in the repository (if the image name it's not a URL then push it in Docker.io).
My new Cloud-build.yml:
steps:
- name: 'docker/compose:1.28.2'
args: [
'-p', 'us-central1-docker.pkg.dev/${PROJECT_ID}/app-destripador',
'-f', './cloud_run/docker-compose.devapp.yml',
'up', '--build', 'web'
]
- name: 'gcr.io/cloud-builders/docker'
args: [
'tag',
'bank_anon_web_dev_build',
'us-central1-docker.pkg.dev/${PROJECT_ID}/app-destripador/bank_anon_web_dev_build'
]
images: ['us-central1-docker.pkg.dev/${PROJECT_ID}/app-destripador/bank_anon_web_dev_build']
Hope anyone need undestand GCP Cloud build using docker-compose can help it, because every guide in the web not explicate this last part.
1.I was trying to run the UnitTesting on GitHub action. After I run the script to connect the http://127.0.0.1:5000/, I can not input any commands anymore(Unless open another terminal). I was wondering if there is any way can input the command and execute this command after connecting the port http://127.0.0.1:5000/? Or does Github Action support run in different terminals?
2.Here is my yml code:
name: UnitTesting
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install Python 3
uses: actions/setup-python#v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirement.txt
- name: Run server
run: |
cd Flask-backend
nohup python3 app.py
sleep
- name: Run Unit test
run: |
pytest
Your command does not run in the background.
You need to change it to
nohup python3 app.py & &>/dev/null
and I believe sleep requires an argument, like sleep 3
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.
I am in the final steps of deploying a django website. It uses docker to run it and I'm finally deploying it through heroku. I run into an error when running "git push heroku master". I receive "Your app does not include a heroku.yml build manifest. To deploy your app, either create a heroku.yml: https://devcenter.heroku.com/articles/build-docker-images-heroku-yml". This is odd as I do in fact have a heroku.yml app.
heroku.yml
setup:
addons:
- plan: heroku-postgresql
build:
docker:
web: Dockerfile
release:
image: web
command:
- python manage.py collectstatic --noinput
run:
web: gunicorn books.wsgi
The tutorial I am following is using "gunicorn bookstore_project.wsgi" but I used books.wsgi as that is the directory my website is in. Neither worked.
this happened to me when i pushed the wrong branch to heroku. I was testing in the develop branch but pushing master which had not heroku.yml.
pervious gitlab-ci
stages:
- staging
staging:
stage: staging
image: ruby:latest
script:
- git remote add heroku https://heroku:$HEROKU_API_KEY#git.heroku.com/$PROJECT.git
- git push -f heroku master
only:
- develop
actual gitlab-ci
stages:
- staging
staging:
stage: staging
image: ruby:latest
script:
- git remote add heroku https://heroku:$HEROKU_API_KEY#git.heroku.com/$PROJECT.git
- git push -f heroku develop:master
only:
- develop