From 720e94f5d588fd24b7dab2b0f50534401aa70835 Mon Sep 17 00:00:00 2001 From: filipopo Date: Sat, 14 Dec 2024 18:51:21 +0100 Subject: [PATCH] Fix pipelines --- .github/workflows/cd.yaml | 23 +++++++----- .github/workflows/{ci.yaml => ci - app.yaml} | 20 +++-------- .github/workflows/ci - code.yaml | 26 ++++++++++++++ .github/workflows/ci - nginx.yaml | 38 ++++++++++++++++++++ 4 files changed, 83 insertions(+), 24 deletions(-) rename .github/workflows/{ci.yaml => ci - app.yaml} (73%) create mode 100644 .github/workflows/ci - code.yaml create mode 100644 .github/workflows/ci - nginx.yaml diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 586493e..a3b98d4 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -29,16 +29,20 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + - name: Set up CDK for Terraform - run: npm install -g cdktf-cli + run: | + pip install --user pipenv + npm install -g cdktf-cli - name: cdktf synth - run: cdktf synth + run: | + pipenv install + cdktf synth working-directory: cdktf - - name: Set up Terraform - uses: hashicorp/setup-terraform@v3 - - name: Make Terraform plan run: | terraform init @@ -71,6 +75,9 @@ jobs: - name: Deploy run: | - terraform -chdir=cdktf.out/stacks/urlshortener-stack apply tfplan - sh swa.sh ${{ github.event.inputs.image_tag }} - working-directory: cdktf + terraform init + terraform apply tfplan + working-directory: cdktf.out/stacks/urlshortener-stack + + - name: Upload static files + run: sh swa.sh ${{ github.event.inputs.image_tag }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci - app.yaml similarity index 73% rename from .github/workflows/ci.yaml rename to .github/workflows/ci - app.yaml index d506691..37ad711 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci - app.yaml @@ -1,9 +1,11 @@ -name: CI +name: CI - app on: push: branches: - main + paths: + - 'app/**' jobs: test: @@ -16,12 +18,6 @@ jobs: with: python-version: 3.12 - - name: Install test dependencies - run: pip install flake8 - - - name: Lint code - run: flake8 --extend-ignore=E501 - - name: Install app dependencies run: pip install -r app/requirements.txt @@ -44,8 +40,7 @@ jobs: - name: Build and push Docker images run: | - ACC=filipmania - IMAGE=${ACC}/urlshortener + IMAGE=filipmania/urlshortener docker build -t ${IMAGE}:${GITHUB_RUN_ID} -t ${IMAGE}:latest . docker push ${IMAGE}:${GITHUB_RUN_ID} @@ -59,12 +54,5 @@ jobs: docker push ${IMAGE}:${GITHUB_RUN_ID}-nginx docker push ${IMAGE}:nginx - docker pull nginx:latest - VER=$(docker run --rm nginx:latest nginx -v 2>&1 1>/dev/null | cut -d/ -f2) - - docker build -t ${ACC}/nginx:${VER} -t ${ACC}/nginx:latest -f compose/Dockerfile compose - docker push ${ACC}/nginx:${VER} - docker push ${ACC}/nginx:latest - - name: Save the IMAGE_TAG run: echo "IMAGE_TAG=${GITHUB_RUN_ID}" diff --git a/.github/workflows/ci - code.yaml b/.github/workflows/ci - code.yaml new file mode 100644 index 0000000..a8da768 --- /dev/null +++ b/.github/workflows/ci - code.yaml @@ -0,0 +1,26 @@ +name: CI - code + +on: + push: + branches: + - main + paths: + - 'app/**' + - 'cdktf/**' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Install test dependencies + run: pip install flake8 + + - name: Lint code + run: flake8 --extend-ignore=E501 diff --git a/.github/workflows/ci - nginx.yaml b/.github/workflows/ci - nginx.yaml new file mode 100644 index 0000000..01cf15f --- /dev/null +++ b/.github/workflows/ci - nginx.yaml @@ -0,0 +1,38 @@ +name: CI - nginx + +on: + push: + branches: + - main + paths: + - 'compose/**' + schedule: + - cron: '0 0 * * Mon' + +jobs: + build-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker images + run: | + IMAGE=filipmania/nginx + docker pull nginx:latest + VER=$(docker run --rm nginx:latest nginx -v 2>&1 1>/dev/null | cut -d/ -f2) + + docker build -t ${IMAGE}:${VER} -t ${IMAGE}:latest -f compose/Dockerfile compose + docker push ${IMAGE}:${VER} + docker push ${IMAGE}:latest + + - name: Save the IMAGE_TAG + run: echo "IMAGE_TAG=${GITHUB_RUN_ID}"