Update docker-build-push.yml #12
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: Build and Push Docker Image | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Install yq | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y python3-pip | |
pip3 install yq | |
- name: Read config.yaml and generate Dockerfile | |
id: generate_dockerfile | |
run: | | |
dependencies=$(yq e '.dependencies' config.yaml | tr '\n' ' ') | |
if [ -z "$dependencies" ]; then | |
echo "No dependencies found in config.yaml" | |
exit 1 | |
fi | |
cat > Dockerfile <<EOL | |
FROM python:3.10-slim | |
WORKDIR /app | |
RUN apt-get update && apt-get install -y \\ | |
build-essential \\ | |
libssl-dev \\ | |
libffi-dev \\ | |
python3-dev \\ | |
libyaml-dev \\ | |
&& apt-get clean \\ | |
&& pip install --no-cache-dir --upgrade pip \\ | |
&& pip install --no-cache-dir cython \\ | |
&& pip install --no-cache-dir $dependencies | |
COPY . . | |
ENV PYTHONUNBUFFERED=1 | |
EXPOSE 5000 | |
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"] | |
EOL | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKER_USERNAME }}/code_interpreter:latest | |
${{ secrets.DOCKER_USERNAME }}/code_interpreter:${{ github.sha }} | |
- name: Clean up Docker images | |
run: | | |
docker image prune -f |