Skip to content

Commit

Permalink
Merge pull request #317 from gulfofmaine/change/argo-cd
Browse files Browse the repository at this point in the history
Clean up to make compatible with Argo CD
  • Loading branch information
abkfenris authored Mar 9, 2021
2 parents fcd8388 + 6db4a71 commit 3da182c
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 62 deletions.
115 changes: 104 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ name: CI
on: [push]

jobs:
test:
name: Build and test
build:
name: Build
runs-on: ubuntu-18.04
timeout-minutes: 15

steps:
- name: Checkout
uses: actions/[email protected]

- 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

Expand All @@ -27,6 +22,14 @@ jobs:
key: buoy-barn-buildx-${{ github.sha }}
restore-keys: |
buoy-barn-buildx-
- name: Cache Docker image
uses: actions/[email protected]
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
Expand All @@ -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/[email protected]

- name: Cache Docker image
uses: actions/[email protected]
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
Expand All @@ -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/[email protected]

- name: Cache Docker image
uses: actions/[email protected]
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
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/[email protected]
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://[email protected]/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 '[email protected]'
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)
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#syntax=docker/dockerfile:1.2
FROM python:3.9.2-slim@sha256:70b693f32768b122a6a5247b0c5d4394da69f5dc3baace93a34860bff00d8ecd

# Output logging faster
Expand All @@ -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
Expand All @@ -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/
Expand All @@ -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"]
CMD ["uwsgi", "--http", ":8080", "--wsgi-file", "buoy_barn/wsgi.py", "--master", "--processes", "4", "--threads", "2", "--uid", "uwsgi", "--gid", "uwsgi"]
2 changes: 0 additions & 2 deletions k8s/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ spec:
volumeMounts:
- name: django-static
mountPath: /static
imagePullSecrets:
- name: docker-hub-secret
volumes:
- name: django-static
emptyDir: {}
10 changes: 1 addition & 9 deletions k8s/base/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 0 additions & 9 deletions k8s/base/ingress_patch.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace: buoy-barn
resources:
- docker-hub-secret.yaml
- cache.yaml
- cache-service.yaml
- deployment.yaml
Expand All @@ -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
2 changes: 0 additions & 2 deletions k8s/base/prefect-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ spec:
volumeMounts:
- name: django-static
mountPath: /static
imagePullSecrets:
- name: docker-hub-secret
volumes:
- name: django-static
emptyDir: {}
2 changes: 0 additions & 2 deletions k8s/base/worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ spec:
volumeMounts:
- name: django-static
mountPath: /static
imagePullSecrets:
- name: docker-hub-secret
volumes:
- name: django-static
emptyDir: {}

0 comments on commit 3da182c

Please sign in to comment.