1
0
Fork 0

ci: new workflow to build and deploy the app

This commit is contained in:
Vojtěch Mareš 2023-07-03 17:59:38 +02:00
parent d454ec8fc9
commit f9f22cd7f4
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
2 changed files with 137 additions and 59 deletions

137
.github/workflows/deploy-to-staging.yml vendored Normal file
View file

@ -0,0 +1,137 @@
name: Deploy to staging from main branch
on:
push:
branches:
- main
tags-ignore:
- '*' # ignore all tags
concurrency:
group: deploy-staging
cancel-in-progress: true
env:
NAMESPACE: backoffice-staging
HELM_VERSION: "3.12.1"
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE: vojtechmares/backoffice
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: set up qemu
uses: docker/setup-qemu-action@v2
- name: set up docker buildx
uses: docker/setup-buildx-action@v2
- name: docker login
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,format=long
type=raw,value=${{ github.ref_name }}-${{ github.sha }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
images: |
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}
- name: build and push
uses: docker/build-push-action@v4
with:
pull: true
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest
deploy:
runs-on: ubuntu-latest
environment:
name: staging
url: https://staging.backoffice.mareshq.com
needs:
- build
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
# Setup kubectl and Helm for Azure
- uses: azure/setup-helm@v3
with:
version: "${{ env.HELM_VERSION }}"
- uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG_CONTENT }}
context: kiwi
# - name: set imagepullsecret
# uses: azure/k8s-create-secret@v4
# with:
# namespace: ${{ env.NAMESPACE }}}
# secret-name: ghcr-io-pull-secret
# container-registry-url: ${{ env.DOCKER_REGISTRY }}
# container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
# container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
# id: create-secret
- name: deploy dry run
run: |
helm upgrade \
--atomic \
--wait=true \
--wait-for-jobs=true \
--timeout 900s \
--dry-run=true \
--install \
--namespace=${{ env.NAMESPACE }} \
-f ./charts/backoffice/values.staging.yaml \
--set image.tag=${{ github.ref_name }}-${{ github.sha }} \
--set secrets.databaseURL=dummy \
--set secrets.nextauthSecret=dummy \
--set secrets.googleClientID=dummy \
--set secrets.googleClientSecret=dummy \
backoffice \
./charts/backoffice
- name: deploy
run: |
helm upgrade \
--atomic \
--wait=true \
--wait-for-jobs=true \
--timeout 900s \
--dry-run=true \
--install \
--namespace=${{ env.NAMESPACE }} \
-f ./charts/backoffice/values.staging.yaml \
--set image.tag=${{ github.ref_name }}-${{ github.sha }} \
--set secrets.databaseURL=${{ secrets.DATABASE_URL }} \
--set secrets.nextauthSecret=${{ secrets.NEXTAUTH_SECRET }} \
--set secrets.googleClientID=${{ secrets.GOOGLE_CLIENT_ID }} \
--set secrets.googleClientSecret=${{ secrets.GOOGLE_CLIENT_SECRET }} \
backoffice \
./charts/backoffice

View file

@ -1,59 +0,0 @@
name: Docker build on main branch
on:
push:
branches:
- main
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE: vojtechmares/backoffice
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
# Setup Docker
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker login
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
# Use repository secrets for username and password, not organization secrets
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,format=long
type=raw,value=${{ github.ref_name }}-${{ github.sha }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
images: |
${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}
- name: Build and push
uses: docker/build-push-action@v4
with:
pull: true
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest