Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from wireapp/staging
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dkovacevic authored Nov 11, 2022
2 parents b50365b + 449af2c commit 6671d03
Show file tree
Hide file tree
Showing 31 changed files with 928 additions and 465 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches-ignore:
- master
- staging

pull_request:

jobs:
docker-build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

# setup docker actions https://github.com/docker/build-push-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build image
id: docker_build
uses: docker/build-push-action@v2
with:
# https://github.com/docker/build-push-action/issues/220
context: .
tags: wire/ci-test-image
push: false
117 changes: 117 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Release Pipeline

on:
release:
types: published

env:
# set docker image for the service - i.e. "wire-bot/poll"
DOCKER_IMAGE: wire-bot/recording-bot
# name of the service in the Dagobah - the value for label name, i.e. "polls"
SERVICE_NAME: recording

jobs:
deploy:
name: Build and deploy service
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set Release Version
# use latest tag as release version
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV

# extract metadata for labels https://github.com/crazy-max/ghaction-docker-meta
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: eu.gcr.io/${{ env.DOCKER_IMAGE }}

# setup docker actions https://github.com/docker/build-push-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# login to GCR repo
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: eu.gcr.io
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# push only if this is indeed a taged release
push: ${{ startsWith(github.ref, 'refs/tags/') }}
build-args: |
release_version=${{ env.RELEASE_VERSION }}
# Checkout our Kubernetes configuration
- name: Checkout Rubicon
uses: actions/checkout@v2
with:
repository: zinfra/rubicon
# currently main branch is develop
ref: develop
path: rubicon
# private repo so use different git token
token: ${{ secrets.RUBICON_GIT_TOKEN }}

# Update version to the one that was just built
- name: Change Version in Rubicon
env:
IMAGE: ${{ env.DOCKER_IMAGE }}
SERVICE: ${{ env.SERVICE_NAME }}
VERSION: ${{ env.RELEASE_VERSION }}
run: |
# go to directory with configuration
cd "rubicon/prod/services/$SERVICE"
# escape literals for the sed and set output with GCR
export SED_PREPARED=$(echo $IMAGE | awk '{ gsub("/", "\\/", $1); print "eu.gcr.io\\/"$1 }')
# update final yaml
sed -i".bak" "s/image: $SED_PREPARED.*/image: $SED_PREPARED:$VERSION/g" "$SERVICE.yaml"
# delete bakup file
rm "$SERVICE.yaml.bak"
# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
service_account_email: [email protected]
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: wire-bot
export_default_credentials: true

# Configure Docker to use the gcloud command-line tool
- name: Configure Docker Google cloud
run: |
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- name: Obtain k8s credentials
env:
GKE_CLUSTER: anayotto
GKE_ZONE: europe-west1-c
run: |
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
# K8s is set up, deploy the app
- name: Deploy the Service
env:
SERVICE: ${{ env.SERVICE_NAME }}
run: |
kubectl apply -f "rubicon/prod/services/$SERVICE/$SERVICE.yaml"
# Commit all data to Rubicon and open PR
- name: Create Rubicon Pull Request
uses: peter-evans/create-pull-request@v3
with:
path: rubicon
branch: ${{ env.SERVICE_NAME }}-release
token: ${{ secrets.RUBICON_GIT_TOKEN }}
labels: version-bump, automerge
title: ${{ env.SERVICE_NAME }} release ${{ env.RELEASE_VERSION }}
commit-message: ${{ env.SERVICE_NAME }} version bump to ${{ env.RELEASE_VERSION }}
body: |
This is automatic version bump from the pipeline.
85 changes: 85 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Staging Deployment

on:
push:
branches:
- staging

env:
# set docker image for the service - i.e. "wire-bot/poll"
DOCKER_IMAGE: wire-bot/recording-bot
# name of the service in the Dagobah - the value for label name, i.e. "polls"
SERVICE_NAME: recording

jobs:
publish:
name: Deploy to staging
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

# use latest tag as release version in the docker container
- name: Set Release Version
run: echo "RELEASE_VERSION=${GITHUB_SHA}" >> $GITHUB_ENV

# extract metadata for labels https://github.com/crazy-max/ghaction-docker-meta
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: eu.gcr.io/${{ env.DOCKER_IMAGE }}

# setup docker actions https://github.com/docker/build-push-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# login to GCR repo
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: eu.gcr.io
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
push: true
build-args: |
release_version=${{ env.RELEASE_VERSION }}
# Setup gcloud CLI
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
service_account_email: [email protected]
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: wire-bot
export_default_credentials: true

# Configure Docker to use the gcloud command-line tool
- name: Configure Docker Google cloud
run: |
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- name: Obtain k8s credentials
env:
GKE_CLUSTER: dagobah
GKE_ZONE: europe-west1-c
run: |
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
# K8s is set up, deploy the app
- name: Deploy the Service
env:
SERVICE: ${{ env.SERVICE_NAME }}
run: |
kubectl delete pod -l app=$SERVICE -n staging
kubectl describe pod -l app=$SERVICE -n staging
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Recording Test.html
recording/
data/
target/
libs/
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

27 changes: 19 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM maven:3.6.3-jdk-8-slim AS build
FROM maven:3-openjdk-11 AS build
LABEL description="Wire Recording bot"
LABEL project="wire-bots:recording"

Expand All @@ -8,15 +8,14 @@ WORKDIR /app
COPY pom.xml ./
RUN mvn verify --fail-never -U

# build stuff
# build
COPY . ./
RUN mvn -Dmaven.test.skip=true package

FROM dejankovacevic/bots.runtime:2.10.3

COPY --from=build /app/target/recording.jar /opt/recording/recording.jar
COPY --from=build /app/recording.yaml /etc/recording/recording.yaml
# runtime stage
FROM wirebot/runtime:1.2.0

RUN mkdir /opt/recording
RUN mkdir /opt/recording/assets
RUN mkdir /opt/recording/avatars
RUN mkdir /opt/recording/html
Expand All @@ -25,6 +24,18 @@ COPY --from=build /app/src/main/resources/assets/* /opt/recording/assets/

WORKDIR /opt/recording

EXPOSE 8080 8081 8082
EXPOSE 8080 8081

# Copy configuration
COPY recording.yaml /opt/recording/

# Copy built target
COPY --from=build /app/target/recording.jar /opt/recording/

# create version file
ARG release_version=development
ENV RELEASE_FILE_PATH=/opt/recording/release.txt
RUN echo $release_version > $RELEASE_FILE_PATH

CMD ["sh", "-c","/usr/bin/java -Djava.library.path=/opt/wire/lib -jar recording.jar server /etc/recording/recording.yaml"]
EXPOSE 8080 8081
ENTRYPOINT ["java", "-jar", "recording.jar", "server", "/opt/recording/recording.yaml"]
9 changes: 5 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
docker build -t $DOCKER_USERNAME/recording-bot:1.0.0 .
docker push $DOCKER_USERNAME/recording-bot
kubectl delete pod -l name=recording -n prod
kubectl get pods -l name=recording -n prod
TAG=1.0.1
NAME=recording-bot

docker build -t $DOCKER_USERNAME/$NAME:$TAG .
docker push $DOCKER_USERNAME/$NAME:$TAG

70 changes: 70 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
- release_version=docker-compose
image: recordingbot
ports:
- 8080:8080
- 8081:8081
environment:
# put here the token used for testing
- SERVICE_TOKEN=some-service-token-from-BE
# - WIRE_API_HOST=
- PUBLIC_URL=http://localhost:8080
# local database
- DB_URL=jdbc:postgresql://db:5432/recording
- DB_USER=recording
- DB_PASSWORD=recording
- APPENDER_TYPE=json-console
depends_on:
- db
- elasticsearch
- kibana
- filebeat

db:
image: postgres:13
# just for local development
environment:
- POSTGRES_USER=recording
- POSTGRES_PASSWORD=recording
- POSTGRES_DB=recording
ports:
- 5432:5432
volumes:
- recording-db:/var/lib/postgresql/data/

elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.11.0
environment:
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
- "discovery.type=single-node"
ports:
- 9200:9200

kibana:
container_name: kb-container
image: docker.elastic.co/kibana/kibana:7.11.0
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
- ELASTICSEARCH_URL=http://elasticsearch:9200
depends_on:
- elasticsearch
ports:
- 5601:5601

filebeat:
image: "docker.elastic.co/beats/filebeat:7.2.0"
user: root
volumes:
- ./filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
- /var/lib/docker:/var/lib/docker:ro
- /var/run/docker.sock:/var/run/docker.sock

volumes:
recording-db:
Loading

0 comments on commit 6671d03

Please sign in to comment.