partey_workadventure/.github/workflows/build-and-deploy.yml

205 lines
7.5 KiB
YAML
Raw Normal View History

2020-04-09 11:00:30 +02:00
name: Build, push and deploy Docker image
on:
2021-05-10 11:56:08 +02:00
push:
2021-06-03 18:34:55 +02:00
branches: [master, develop]
release:
types: [created]
pull_request:
types: [ labeled, synchronize ]
2020-04-09 11:00:30 +02:00
# Enables BuildKit
env:
DOCKER_BUILDKIT: 1
jobs:
build-front:
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
2020-04-09 11:00:30 +02:00
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
2020-04-13 18:15:27 +02:00
# Create a slugified value of the branch
- uses: rlespinasse/github-slug-action@3.1.0
2020-04-13 18:15:27 +02:00
2020-04-09 11:00:30 +02:00
- name: "Build and push front image"
uses: docker/build-push-action@v1
with:
2020-04-09 11:56:29 +02:00
dockerfile: front/Dockerfile
path: ./
2020-04-09 11:00:30 +02:00
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: thecodingmachine/workadventure-front
tags: ${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
2020-04-09 11:00:30 +02:00
add_git_labels: true
build-back:
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
2020-04-09 11:00:30 +02:00
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
2020-04-13 18:15:27 +02:00
# Create a slugified value of the branch
2020-12-04 15:13:35 +01:00
- uses: rlespinasse/github-slug-action@3.1.0
- name: "Build and push back image"
uses: docker/build-push-action@v1
with:
dockerfile: back/Dockerfile
path: ./
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: thecodingmachine/workadventure-back
tags: ${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
2020-12-04 15:13:35 +01:00
add_git_labels: true
build-pusher:
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
2020-12-04 15:13:35 +01:00
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Create a slugified value of the branch
- uses: rlespinasse/github-slug-action@3.1.0
2020-04-13 18:15:27 +02:00
2020-04-09 11:00:30 +02:00
- name: "Build and push back image"
uses: docker/build-push-action@v1
with:
2020-12-09 15:19:22 +01:00
dockerfile: pusher/Dockerfile
path: ./
2020-04-09 11:00:30 +02:00
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
2020-12-09 15:19:22 +01:00
repository: thecodingmachine/workadventure-pusher
tags: ${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
add_git_labels: true
build-uploader:
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Create a slugified value of the branch
- uses: rlespinasse/github-slug-action@3.1.0
- name: "Build and push back image"
uses: docker/build-push-action@v1
with:
dockerfile: uploader/Dockerfile
path: ./
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: thecodingmachine/workadventure-uploader
tags: ${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
add_git_labels: true
2020-07-23 18:43:51 +02:00
build-maps:
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
2020-07-23 18:43:51 +02:00
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Create a slugified value of the branch
2020-12-04 15:13:35 +01:00
- uses: rlespinasse/github-slug-action@3.1.0
2020-07-23 18:43:51 +02:00
- name: "Build and push front image"
uses: docker/build-push-action@v1
with:
dockerfile: maps/Dockerfile
path: maps/
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: thecodingmachine/workadventure-maps
tags: ${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
2020-04-09 11:00:30 +02:00
add_git_labels: true
deeploy:
needs:
- build-front
- build-back
2020-12-11 12:37:11 +01:00
- build-pusher
- build-maps
- build-uploader
2020-04-09 11:00:30 +02:00
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
2020-04-09 11:00:30 +02:00
2020-04-09 11:03:24 +02:00
steps:
2020-04-09 11:00:30 +02:00
- name: Checkout
uses: actions/checkout@v2
2020-04-13 15:44:33 +02:00
# Create a slugified value of the branch
2020-12-09 13:50:18 +01:00
- uses: rlespinasse/github-slug-action@3.1.0
2020-04-13 15:44:33 +02:00
- name: Write certificate
2021-06-11 14:25:02 +02:00
run: echo "${CERTS_PRIVATE_KEY}" > secret.key && chmod 0600 secret.key
env:
CERTS_PRIVATE_KEY: ${{ secrets.CERTS_PRIVATE_KEY }}
- name: Download certificate
2021-06-11 14:44:23 +02:00
run: mkdir secrets && scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i secret.key ubuntu@cert.workadventu.re:./config/live/workadventu.re/* secrets/
2021-06-11 14:52:59 +02:00
- name: Create namespace
uses: steebchen/kubectl@v1.0.0
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_FILE_BASE64 }}
with:
args: create namespace workadventure-${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
continue-on-error: true
- name: Delete old certificates in namespace
uses: steebchen/kubectl@v1.0.0
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_FILE_BASE64 }}
with:
args: -n workadventure-${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }} delete secret certificate-tls
continue-on-error: true
- name: Install certificates in namespace
uses: steebchen/kubectl@v1.0.0
env:
2021-06-11 14:37:43 +02:00
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_FILE_BASE64 }}
with:
args: -n workadventure-${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }} create secret tls certificate-tls --key="secrets/privkey.pem" --cert="secrets/fullchain.pem"
2020-04-09 12:14:06 +02:00
- name: Deploy
uses: thecodingmachine/deeployer-action@master
2020-04-09 14:21:43 +02:00
env:
KUBE_CONFIG_FILE: ${{ secrets.KUBE_CONFIG_FILE }}
2020-10-14 12:25:05 +02:00
ADMIN_API_TOKEN: ${{ secrets.ADMIN_API_TOKEN }}
JITSI_ISS: ${{ secrets.JITSI_ISS }}
JITSI_URL: ${{ secrets.JITSI_URL }}
SECRET_JITSI_KEY: ${{ secrets.SECRET_JITSI_KEY }}
TURN_STATIC_AUTH_SECRET: ${{ secrets.TURN_STATIC_AUTH_SECRET }}
DEPLOY_REF: ${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
2021-09-16 17:03:49 +02:00
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
POSTHOG_URL: ${{ secrets.POSTHOG_URL }}
2020-04-09 12:14:06 +02:00
with:
namespace: workadventure-${{ github.event_name == 'pull_request' && env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
- name: Add a comment in PR
2020-04-13 18:33:27 +02:00
uses: unsplash/comment-on-pr@v1.2.0
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: "Environment deployed at https://play-${{ env.GITHUB_HEAD_REF_SLUG }}.test.workadventu.re \nTests available at https://maps-${{ env.GITHUB_HEAD_REF_SLUG }}.test.workadventu.re/tests"