ci(Master): Adding correct var for is_prod in pipe #9
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: Production-Pipeline-Dockerhub | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
env: | |
IMAGE_NAME: mp3_converter | |
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | |
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} | |
DATABASE_URL: "" | |
TEST_DATABASE_URL: ${{vars.TEST_DATABASE_URL}} | |
SECRET_KEY: "" | |
ALGORITHM: "" | |
ACCESS_TOKEN_EXPIRE_MINUTES: 30 | |
POSTGRES_USER: "" | |
POSTGRES_PASSWORD: "" | |
POSTGRES_DB: "" | |
PAGE: "1" | |
PAGE_SIZE: "10" | |
ORDERING: "-created_at" | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_DB: ${{vars.TEST_POSTGRES_DB}} | |
POSTGRES_PASSWORD: ${{vars.TEST_POSTGRES_PASSWORD}} | |
POSTGRES_USER: ${{vars.TEST_POSTGRES_USER}} | |
ports: | |
- 5432:5432 | |
steps: | |
- name: Cloning the Repository | |
uses: actions/checkout@v3 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.11.1" | |
- name: Install Poetry | |
run: pipx install poetry | |
- name: Install Dependencies | |
run: poetry install | |
- name: Run tests | |
run: poetry run task test | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
push-to-dockerhub: | |
runs-on: ubuntu-latest | |
needs: build-and-test | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.11.1" | |
- name: Install Poetry | |
run: pipx install poetry | |
- name: Get Version from pyproject.toml | |
id: get-version | |
run: | | |
VERSION=$(poetry version --short) | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
echo "::set-output name=version::${VERSION}" | |
- name: Build Docker Image | |
id: build-image | |
env: | |
IMAGE_NAME: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }} | |
VERSION: ${{ steps.get-version.outputs.version }} | |
run: | | |
docker build -t $IMAGE_NAME:latest -t $IMAGE_NAME:$VERSION . | |
- name: Docker Hub Login | |
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin | |
- name: docker images | |
run: docker images | |
- name: Tag and Push Docker Image to Docker Hub | |
run: | | |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }} --all-tags | |
Update-Image-Tag-in-Deployment: | |
runs-on: ubuntu-latest | |
needs: [build-and-test, push-to-dockerhub] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.ACCOUNT_MODIFY_TOKEN }} | |
fetch-depth: 0 | |
- name: Install Poetry | |
run: pipx install poetry | |
- name: Get Version from pyproject.toml | |
id: get-version | |
run: | | |
VERSION=$(poetry version --short) | |
echo "NEW_IMAGE_TAG=${VERSION}" >> $GITHUB_ENV | |
echo "::set-output name=new_version::${VERSION}" | |
- name: Checkout GitOps Branch | |
run: | | |
git fetch origin | |
git checkout gitops | |
- name: Update Image Tag in Deployment | |
run: | | |
sed -i "s|image: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:.*|image: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.NEW_IMAGE_TAG }}|" k8s/deployment.yaml | |
- name: Check deployment.yaml after sed | |
run: cat k8s/deployment.yaml | |
- name: Git Status | |
run: git status | |
- name: Git Config | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "CI Bot" | |
- name: Commit and Push Changes | |
run: | | |
git add k8s/deployment.yaml | |
git commit -m "Updating the image tag: ${{ env.NEW_IMAGE_TAG }}" | |
git push origin gitops |