Skip to content

Commit

Permalink
Merge pull request #10 from plonegovbr/new-deploy
Browse files Browse the repository at this point in the history
New deploy
  • Loading branch information
ericof authored Mar 16, 2023
2 parents a8bb135 + 0a96d2b commit 2efdf36
Show file tree
Hide file tree
Showing 12 changed files with 622 additions and 281 deletions.
95 changes: 60 additions & 35 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
name: Backend CI
name: Backend testing
run-name: Backend testing by @${{ github.actor }}

on:
push:
paths:
- "backend/**"
- ".github/workflows/backend.yml"

env:
PYTHON_VERSION: 3.11
PLONE_VERSION: 6.0.2
IMAGE_NAME_SUFFIX: backend

defaults:
run:
working-directory: ./backend

jobs:

meta:
runs-on: ubuntu-latest
outputs:
ENVIRONMENT: ${{ steps.vars.outputs.ENVIRONMENT }}
STACK_NAME: ${{ steps.vars.outputs.STACK_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set Env Vars
id: vars
run: |
ENVIRONMENT=${{ vars.LIVE_ENV }}
echo "ENVIRONMENT=${ENVIRONMENT}" >> $GITHUB_OUTPUT
echo "STACK_NAME=${ENVIRONMENT//./-}" >> $GITHUB_OUTPUT
black:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -58,31 +84,20 @@ jobs:

tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- 3.11
plone:
- "6.0.0.2"

defaults:
run:
working-directory: ./backend

steps:

- uses: actions/checkout@v3

- name: Setup Plone ${{ matrix.plone }} with Python ${{ matrix.python }}
- name: Setup Plone ${{ env.PLONE_VERSION }} with Python ${{ env.PYTHON_VERSION }}
uses: plone/setup-plone@v2.0.0
with:
python-version: ${{ matrix.python }}
plone-version: ${{ matrix.plone }}
python-version: ${{ env.PYTHON_VERSION }}
plone-version: ${{ env.PLONE_VERSION }}

- name: Install package
run: |
pip install "plone.app.testing" -c https://dist.plone.org/release/${{ matrix.plone }}/constraints.txt
pip install "plone.app.testing" -c https://dist.plone.org/release/${{ env.PLONE_VERSION }}/constraints.txt
pip install -e "src/ploneorgbr.core[test]"
- name: Run tests
Expand All @@ -91,7 +106,13 @@ jobs:
release:
runs-on: ubuntu-latest
needs: [black, flake8, isort, zpretty, tests]
needs:
- meta
- black
- flake8
- isort
- zpretty
- tests

steps:

Expand All @@ -103,57 +124,61 @@ jobs:
uses: docker/metadata-action@v4
with:
images: |
ploneorgbr/site-backend
labels: |
org.label-schema.docker.cmd=docker run -d -p 8080:8080 ploneorgbr/site-backend:latest
${{ vars.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
flavor: |
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
context: backend
file: backend/Dockerfile
build-args: |
PLONE_VERSION=${{ env.PLONE_VERSION }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs:
- release
runs-on: ubuntu-latest
environment: plone.org.br
- meta
environment:
name: ${{ needs.meta.outputs.ENVIRONMENT }}
url: ${{ needs.meta.outputs.ENVIRONMENT }}
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Deploy to plone.org.br
- name: Deploy to cluster
uses: kitconcept/docker-stack-deploy@v1.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
remote_host: ${{ secrets.DEPLOY_HOST }}
remote_port: ${{ secrets.DEPLOY_PORT }}
remote_user: ${{ secrets.DEPLOY_USER }}
remote_private_key: ${{ secrets.DEPLOY_SSH }}
stack_file: "devops/stacks/plone.org.br.yml"
stack_name: "plonebr"
stack_file: devops/stacks/${{ needs.meta.outputs.ENVIRONMENT }}.yml
stack_name: ${{ needs.meta.outputs.STACK_NAME }}
stack_param: ${{ github.ref_name }}
env_file: ${{ secrets.ENV_FILE }}
deploy_timeout: 480
116 changes: 62 additions & 54 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
name: Frontend CI

name: Frontend testing
run-name: Frontend testing by @${{ github.actor }}
on:
workflow_dispatch:
push:
paths:
- "frontend/**"
- ".github/workflows/frontend.yml"

env:
node-version: 16.x
NODE_VERSION: "16.x"
VOLTO_VERSION: "16.16.0"
IMAGE_NAME_SUFFIX: frontend

jobs:

eslint:
meta:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
outputs:
ENVIRONMENT: ${{ steps.vars.outputs.ENVIRONMENT }}
STACK_NAME: ${{ steps.vars.outputs.STACK_NAME }}
steps:
- name: Checkout codebase
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ env.node-version }}
- name: Set Env Vars
id: vars
run: |
ENVIRONMENT=${{ vars.STG_ENV }}
echo "ENVIRONMENT=${ENVIRONMENT}" >> $GITHUB_OUTPUT
echo "STACK_NAME=${ENVIRONMENT//./-}" >> $GITHUB_OUTPUT
codeanalysis:
runs-on: ubuntu-latest

steps:
- name: Main checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'

- name: Install packages
run: make install

- name: Lint
run: yarn run lint:ci

- name: i18n
run: yarn run i18n:ci
- name: Linting
run: |
make install-frontend
make lint-frontend
prettier:
unit:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- name: Checkout codebase
uses: actions/checkout@v3

- name: Run Prettier
run: npx prettier@2.0.5 --single-quote --check 'src/**/*.{js,jsx,ts,tsx,css,scss}' --config=package.json

tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- name: Checkout codebase
uses: actions/checkout@v3

- name: Use Node.js ${{ env.node-version }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'

- name: Install packages
run: make install

- name: Test
run: yarn run test:ci
run: |
make install-frontend
make test-frontend-ci
release:
runs-on: ubuntu-latest
needs: [eslint, prettier, tests]
needs:
- meta
- codeanalysis
- unit

steps:

Expand All @@ -84,57 +85,64 @@ jobs:
uses: docker/metadata-action@v4
with:
images: |
ploneorgbr/site-frontend
labels: |
org.label-schema.docker.cmd=docker run -d -p 3000:3000 ploneorgbr/site-frontend:latest
${{ vars.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
flavor: |
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
context: frontend/
file: frontend/Dockerfile
build-args: |
VOLTO_VERSION=${{ env.VOLTO_VERSION }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: $${{ steps.meta.outputs.labels }}

deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs:
- release
runs-on: ubuntu-latest
environment: plone.org.br
- meta
environment:
name: ${{ needs.meta.outputs.ENVIRONMENT }}
url: ${{ needs.meta.outputs.ENVIRONMENT }}
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Deploy to plone.org.br
- name: Deploy to cluster
uses: kitconcept/docker-stack-deploy@v1.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
remote_host: ${{ secrets.DEPLOY_HOST }}
remote_port: ${{ secrets.DEPLOY_PORT }}
remote_user: ${{ secrets.DEPLOY_USER }}
remote_private_key: ${{ secrets.DEPLOY_SSH }}
stack_file: "devops/stacks/plone.org.br.yml"
stack_name: "plonebr"
stack_file: devops/stacks/${{ needs.meta.outputs.ENVIRONMENT }}.yml
stack_name: ${{ needs.meta.outputs.STACK_NAME }}
stack_param: ${{ github.ref_name }}
env_file: ${{ secrets.ENV_FILE }}
deploy_timeout: 480
Loading

0 comments on commit 2efdf36

Please sign in to comment.