Skip to content

Commit

Permalink
Merge pull request #72 from wireapp/staging
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dkovacevic authored Aug 4, 2021
2 parents efb3fca + 1bf7647 commit b2a1a3e
Show file tree
Hide file tree
Showing 160 changed files with 44,123 additions and 561 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Dockerfile
docker-compose.yml
README.md
roman.iml
node_modules
build
*.iml
56 changes: 53 additions & 3 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release Pipeline

on:
release:
types: published
types: [published]

env:
DOCKER_IMAGE: wire-bot/roman
Expand Down Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# login to GCR repo
- name: Login to DockerHub
- name: Login to GCR
uses: docker/login-action@v1
with:
registry: eu.gcr.io
Expand Down Expand Up @@ -124,8 +124,58 @@ jobs:
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: ${{ env.SERVICE_NAME }} release pipeline
author_name: ${{ env.SERVICE_NAME }} Production Deployment
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_RELEASE }}
# Notify every release
if: always()

quay_publish:
name: Quay Publish Pipeline
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: quay.io/wire/${{ env.SERVICE_NAME }}

# 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: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

- 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 }}
# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: ${{ env.SERVICE_NAME }} Quay Production Publish
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_RELEASE }}
# Send message only if previous step failed
if: always()
55 changes: 55 additions & 0 deletions .github/workflows/quay.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Quay Deployment

on:
# manual dispatch
workflow_dispatch:
inputs:
tag:
description: 'Docker image tag.'
required: true
jobs:
publish:
name: Deploy to staging
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

# 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: quay.io/wire/roman

# 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: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
tags: quay.io/wire/roman:${{ github.event.inputs.tag }}
labels: ${{ steps.docker_meta.outputs.labels }}
push: true
build-args: |
release_version=${{ github.event.inputs.tag }}
# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: Roman Quay Custom Tag Pipeline
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_CI }}
# Send message only if previous step failed
if: always()
124 changes: 95 additions & 29 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,45 @@ on:
- staging

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

# common setup
GKE_PROJECT: wire-bot
GKE_ZONE: europe-west1-c
GCR_REPOSITORY: eu.gcr.io
GKE_CLUSTER: dagobah

NAMESPACE: staging

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
- name: Setup Environment
run: |
echo "RELEASE_VERSION=${GITHUB_SHA}" >> $GITHUB_ENV
echo "DOCKER_IMAGE=${{ env.GCR_REPOSITORY }}/${{ env.GKE_PROJECT }}/${{ env.SERVICE_NAME }}" >> $GITHUB_ENV
echo "DEPLOYMENT=${{ env.SERVICE_NAME }}-app" >> $GITHUB_ENV
echo "CONTAINER=${{ env.SERVICE_NAME }}" >> $GITHUB_ENV
# extract metadata for labels https://github.com/crazy-max/ghaction-docker-meta
- name: Docker meta
- name: Create tags and labels
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: eu.gcr.io/${{ env.DOCKER_IMAGE }}
images: ${{ 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

- name: Login to GCR
uses: docker/login-action@v1
with:
registry: eu.gcr.io
registry: ${{ env.GCR_REPOSITORY }}
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}

Expand All @@ -52,44 +58,104 @@ jobs:
build-args: |
release_version=${{ env.RELEASE_VERSION }}
# Setup gcloud CLI
- name: Prepare new name of the image
run: |
echo "NEW_IMAGE=${{ env.DOCKER_IMAGE }}@${{ steps.docker_build.outputs.digest }}" >> $GITHUB_ENV
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
service_account_email: kubernetes-deployment-agent@wire-bot.iam.gserviceaccount.com
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: wire-bot
project_id: ${{ env.GKE_PROJECT }}
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
- name: Login to K8s
run: |
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE"
gcloud container clusters get-credentials "${GKE_CLUSTER}" --zone "${GKE_ZONE}";
kubectl config set-context --current --namespace="${NAMESPACE}";
# K8s is set up, deploy the app
- name: Deploy the Service
run: |
kubectl set image deployment "${DEPLOYMENT}" "${CONTAINER}=${NEW_IMAGE}";
- name: Check that the service started
id: deployment_check
continue-on-error: true
env:
SERVICE: ${{ env.SERVICE_NAME }}
TIMEOUT: 5m
run: |
kubectl delete pod -l app=$SERVICE -n staging
kubectl describe pod -l app=$SERVICE -n staging
kubectl rollout status deployment "${DEPLOYMENT}" -w --timeout="${TIMEOUT}";
- name: Undo Failed Deployment
if: steps.deployment_check.outcome == 'failure'
run: |
kubectl rollout undo deployment "${DEPLOYMENT}"
- name: Indicate failure if the deployment check failed
if: steps.deployment_check.outcome == 'failure'
run: |
echo "steps.deployment_check failed!"
exit 1
# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: ${{ env.SERVICE_NAME }} staging pipeline
author_name: ${{ env.SERVICE_NAME }} Staging Deployment
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_CI }}
# Send message only if previous step failed
if: always()

quay_publish:
name: Quay Publish Pipeline
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- 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: quay.io/wire/${{ env.SERVICE_NAME }}

# 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: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

- 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 }}
# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: ${{ env.SERVICE_NAME }} Quay Staging Publish
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_RELEASE }}
# Send message only if previous step failed
if: always()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env.prod
target/
data/
.idea/
Expand Down
28 changes: 18 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
FROM maven:3.6.3-jdk-8-slim AS build
LABEL description="Wire Roman"
LABEL project="wire-bots:roman"
FROM node:alpine as frontend-build
COPY frontend/ ./frontend
WORKDIR ./frontend
RUN npm i
RUN npm run build

FROM maven:3-openjdk-11 AS build
WORKDIR /app

COPY pom.xml ./
COPY backend/pom.xml ./

RUN mvn verify --fail-never -U

COPY . ./
COPY backend/ ./

RUN mvn -Dmaven.test.skip=true package

FROM wirebot/runtime

COPY --from=build /app/target/roman.jar /opt/roman/
FROM wirebot/runtime AS runtime
LABEL description="Wire Roman"
LABEL project="wire-bots:roman"

COPY roman.yaml /etc/roman/
# Copy backend
COPY --from=build /app/target/roman.jar /opt/roman/backend/
COPY backend/roman.yaml /etc/roman/
# Copy frontend
ENV FRONTEND_PATH=/opt/roman/frontend
COPY --from=frontend-build ./frontend/build $FRONTEND_PATH

# create version file
ARG release_version=development
Expand All @@ -25,7 +33,7 @@ RUN echo $release_version > /opt/roman/release.txt

# ENV APPENDER_TYPE=json-console

WORKDIR /opt/roman
WORKDIR /opt/roman/backend/

EXPOSE 8080 8081 8082

Expand Down
Loading

0 comments on commit b2a1a3e

Please sign in to comment.