From 6db4a7111473ed9c108f1c97e41c94470cbf2668 Mon Sep 17 00:00:00 2001 From: Alex Kerney Date: Mon, 8 Mar 2021 20:26:47 -0500 Subject: [PATCH] Clean up to make compatible with Argo CD --- .github/workflows/ci.yaml | 115 ++++++++++++++++++++++++++++++++---- Makefile | 6 +- app/Dockerfile | 16 ++--- k8s/base/deployment.yaml | 2 - k8s/base/ingress.yaml | 10 +--- k8s/base/ingress_patch.yaml | 9 --- k8s/base/kustomization.yaml | 17 ------ k8s/base/prefect-agent.yaml | 2 - k8s/base/worker.yaml | 2 - 9 files changed, 117 insertions(+), 62 deletions(-) delete mode 100644 k8s/base/ingress_patch.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a54a5216..4e34b189 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,8 +3,8 @@ name: CI on: [push] jobs: - test: - name: Build and test + build: + name: Build runs-on: ubuntu-18.04 timeout-minutes: 15 @@ -12,11 +12,6 @@ jobs: - name: Checkout uses: actions/checkout@v2.3.4 - - name: Setup Docker Data - run: | - mkdir docker-data - cat <<< "${{ secrets.DOCKER_DATA_SECRET }}" > docker-data/secret.env - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -27,6 +22,14 @@ jobs: key: buoy-barn-buildx-${{ github.sha }} restore-keys: | buoy-barn-buildx- + + - name: Cache Docker image + uses: actions/cache@v2.1.4 + with: + path: /tmp/myimage.tar + key: mariners-dashboard-image-${{ github.sha }} + restore-keys: | + mariners-dashboard-image- - name: Login to Docker Hub uses: docker/login-action@v1 @@ -43,7 +46,40 @@ jobs: tags: gmri/neracoos-buoy-barn:latest cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new - outputs: type=docker + outputs: type=docker,dest=/tmp/myimage.tar + + - name: Move Docker Cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + test: + name: Unit Tests + runs-on: ubuntu-20.04 + timeout-minutes: 15 + needs: build + + steps: + - name: "Checkout" + uses: actions/checkout@v2.3.4 + + - name: Cache Docker image + uses: actions/cache@v2.1.4 + with: + path: /tmp/myimage.tar + key: mariners-dashboard-image-${{ github.sha }} + restore-keys: | + mariners-dashboard-image- + + - name: Load Docker image + run: | + docker load --input /tmp/myimage.tar + docker image ls -a + + - name: Setup Docker Data + run: | + mkdir docker-data + cat <<< "${{ secrets.DOCKER_DATA_SECRET }}" > docker-data/secret.env - name: Bring up server run: docker-compose up -d @@ -62,7 +98,64 @@ jobs: env: CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} - - name: Move Docker Cache + deploy: + name: Build and Push tagged image to Docker Hub, and update Argo config + runs-on: ubuntu-20.04 + needs: test + environment: + name: Buoy Barn via Argo CD + url: https://buoy-barn.neracoos.org/admin/ + if: | + github.repository == 'gulfofmaine/buoy-barn' + && contains(github.ref, 'refs/tags/v') + + steps: + - name: "Checkout" + uses: actions/checkout@v2.3.4 + + - name: Cache Docker image + uses: actions/cache@v2.1.4 + with: + path: /tmp/myimage.tar + key: mariners-dashboard-image-${{ github.sha }} + restore-keys: | + mariners-dashboard-image- + + - name: Load Docker image run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache \ No newline at end of file + docker load --input /tmp/myimage.tar + docker image ls -a + + - name: "Login to Docker Hub" + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Get tag name + uses: olegtarasov/get-tag@v2.1 + id: tagName + + - name: Tag Docker image + run: docker tag gmri/neracoos-buoy-barn gmri/neracoos-buoy-barn:${{ steps.tagName.outputs.tag }} + + - name: Push Docker image + run: docker push gmri/neracoos-buoy-barn:${{ steps.tagName.outputs.tag }} + + - name: Make GitOps directory + run: mkdir gitops + + - name: Clone GitOps config repo + run: git clone "https://$GITOPS_TOKEN@github.com/gulfofmaine/neracoos-do-cd.git" + working-directory: ./gitops + env: + GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }} + + - name: Update GitOps config repo + working-directory: ./gitops/neracoos-do-cd + run: | + sed -i 's/?ref=.\+/?ref=${{ steps.tagName.outputs.tag }}/' apps/buoy-barn/kustomization.yaml + sed -i 's/newTag: .\+/newTag: ${{ steps.tagName.outputs.tag }}/' apps/buoy-barn/kustomization.yaml + git config --global user.email 'neracoos-buoy-barn-ci@gmri.org' + git config --global user.name 'NERACOOS Buoy Barn CI' + git diff --exit-code && echo 'Already Deployed' || (git commit -am 'Upgrade Buoy Barn to ${{ steps.tagName.outputs.tag }}' && git push) diff --git a/Makefile b/Makefile index 6e5dcc0e..37581ca8 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ build: - docker-compose build + docker buildx bake up: down build - # docker-compose up -d --build docker-compose up -d docker-compose logs -f @@ -22,7 +21,8 @@ migrate: docker-compose exec web python manage.py migrate prune: - docker volume rm $(shell docker volum ls -qf dangling=true) + docker volume rm $(shell docker volume ls -qf dangling=true) + docker buildx prune -f docker system prune -a load: diff --git a/app/Dockerfile b/app/Dockerfile index d0c3d952..8c8cce4c 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,3 +1,4 @@ +#syntax=docker/dockerfile:1.2 FROM python:3.9.2-slim@sha256:70b693f32768b122a6a5247b0c5d4394da69f5dc3baace93a34860bff00d8ecd # Output logging faster @@ -10,15 +11,15 @@ ENV PYTHONWARNINGS always ENV POETRY_VIRTUALENVS_CREATE false # geodjango spatial requirements -RUN apt-get update && apt-get install -y --no-install-recommends \ +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ binutils=2.31.1-16 \ libproj-dev=5.2.0-1 \ gdal-bin=2.4.0+dfsg-1+b1 \ - build-essential=12.6 \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + build-essential=12.6 -RUN pip install poetry==1.0.3 \ +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install poetry==1.1.5 \ && groupadd uwsgi && useradd -g uwsgi uwsgi # Working directory @@ -27,7 +28,8 @@ WORKDIR /app # Install requirements COPY ./pyproject.toml ./poetry.lock /app/ -RUN poetry install --no-interaction +RUN --mount=type=cache,target=/root/.cache/pypoetry \ + poetry install --no-interaction # Copy app to working directory COPY ./ /app/ @@ -36,4 +38,4 @@ RUN chown -R uwsgi:uwsgi /app ENTRYPOINT ["/app/utils/entrypoint.sh"] -CMD ["uwsgi", "--http", ":8080", "--wsgi-file", "buoy_barn/wsgi.py", "--master", "--processes", "4", "--threads", "2", "--uid", "uwsgi", "--gid", "uwsgi"] \ No newline at end of file +CMD ["uwsgi", "--http", ":8080", "--wsgi-file", "buoy_barn/wsgi.py", "--master", "--processes", "4", "--threads", "2", "--uid", "uwsgi", "--gid", "uwsgi"] diff --git a/k8s/base/deployment.yaml b/k8s/base/deployment.yaml index e69563fe..2f401eb8 100644 --- a/k8s/base/deployment.yaml +++ b/k8s/base/deployment.yaml @@ -38,8 +38,6 @@ spec: volumeMounts: - name: django-static mountPath: /static - imagePullSecrets: - - name: docker-hub-secret volumes: - name: django-static emptyDir: {} diff --git a/k8s/base/ingress.yaml b/k8s/base/ingress.yaml index 6ecf7e85..bde09da3 100644 --- a/k8s/base/ingress.yaml +++ b/k8s/base/ingress.yaml @@ -2,17 +2,9 @@ apiVersion: extensions/v1beta1 kind: Ingress metadata: name: buoy-barn-ingress - annotations: - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/ssl-redirect: "false" - nginx.ingress.kubernetes.io/enable-cors: "true" - nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS" - # nginx.ingress.kubernetes.io/cors-allow-origin: "http://localhost http://mariners.neracoos.org https://mariners.neracoos.org http://localhost:3000" - nginx.ingress.kubernetes.io/cors-allow-origin: "*" spec: rules: - - host: buoybarn.neracoos.org - http: + - http: paths: - path: / backend: diff --git a/k8s/base/ingress_patch.yaml b/k8s/base/ingress_patch.yaml deleted file mode 100644 index 7aa0edc4..00000000 --- a/k8s/base/ingress_patch.yaml +++ /dev/null @@ -1,9 +0,0 @@ -- op: add - path: /spec/rules/0/host - value: buoybarn.neracoos.org -- op: add - path: /metadata/annotations/certmanager.k8s.io~1cluster-issuer - value: letsencrypt-prod -- op: add - path: /spec/tls - value: [{ hosts: [buoybarn.neracoos.org], secretName: letsencrypt-prod }] diff --git a/k8s/base/kustomization.yaml b/k8s/base/kustomization.yaml index 7eede8cf..8676a8b9 100644 --- a/k8s/base/kustomization.yaml +++ b/k8s/base/kustomization.yaml @@ -1,6 +1,5 @@ namespace: buoy-barn resources: - - docker-hub-secret.yaml - cache.yaml - cache-service.yaml - deployment.yaml @@ -12,19 +11,3 @@ configMapGenerator: - name: buoy-barn-config envs: - config.env -secretGenerator: - - name: buoy-barn-secrets - envs: - - secret.env -commonLabels: - app: buoy-barn - maintainer: akerney - funder: NERACOOS - project: Mariners_dashboard -patchesJson6902: - - target: - name: buoy-barn-ingress - group: extensions - version: v1beta1 - kind: Ingress - path: ingress_patch.yaml diff --git a/k8s/base/prefect-agent.yaml b/k8s/base/prefect-agent.yaml index 05908387..6f94a12b 100644 --- a/k8s/base/prefect-agent.yaml +++ b/k8s/base/prefect-agent.yaml @@ -41,8 +41,6 @@ spec: volumeMounts: - name: django-static mountPath: /static - imagePullSecrets: - - name: docker-hub-secret volumes: - name: django-static emptyDir: {} diff --git a/k8s/base/worker.yaml b/k8s/base/worker.yaml index e2c8e5f8..8787f797 100644 --- a/k8s/base/worker.yaml +++ b/k8s/base/worker.yaml @@ -42,8 +42,6 @@ spec: volumeMounts: - name: django-static mountPath: /static - imagePullSecrets: - - name: docker-hub-secret volumes: - name: django-static emptyDir: {}