Skip to content

Commit

Permalink
Merge pull request #32 from wireapp/staging
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
dkovacevic authored Feb 5, 2021
2 parents a9406a9 + ac01a92 commit d37225e
Show file tree
Hide file tree
Showing 32 changed files with 569 additions and 255 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.idea
target
Dockerfile
docker-compose.yml
README.md
roman.iml
19 changes: 13 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ on:

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

- name: Build docker image
uses: docker/build-push-action@v1
# 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:
# login to repo
repository: wire/ci-test-image
# do not push image
# https://github.com/docker/build-push-action/issues/220
context: .
tags: wire/ci-test-image
push: false

# Send webhook to Wire using Slack Bot
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/master.yml

This file was deleted.

52 changes: 31 additions & 21 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,50 @@ on:
types: published

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

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

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

- name: Build and publish docker image
uses: docker/build-push-action@v1
# 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:
# set docker image
repository: ${{ env.DOCKER_IMAGE }}
# use GCR repository
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}
# pass release_version
build_args: release_version=${{ env.RELEASE_VERSION }}
# tag the image with latest git tag
tag_with_ref: true
# add labels based on the build - see https://github.com/opencontainers/image-spec/blob/master/annotations.md
add_git_labels: true
# push only if this is tagged release

- 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
Expand Down Expand Up @@ -68,13 +78,13 @@ jobs:
rm "$SERVICE.yaml.bak"
# Setup gcloud CLI
- name: Setup Google Cloud CLI
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
version: '286.0.0'
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
Expand All @@ -98,7 +108,7 @@ jobs:
# Commit all data to Rubicon and open PR
- name: Create Rubicon Pull Request
uses: peter-evans/create-pull-request@v2
uses: peter-evans/create-pull-request@v3
with:
path: rubicon
branch: ${{ env.SERVICE_NAME }}-release
Expand Down
65 changes: 38 additions & 27 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,81 @@ on:
- staging

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

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

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

- name: Build docker image, push
uses: docker/build-push-action@v1
# 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:
# set docker image
repository: ${{ env.DOCKER_IMAGE }}
# use GCR repository
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.GCR_ACCESS_JSON }}
# pass release_version
build_args: release_version=${{ env.RELEASE_VERSION }}
# tag the image with name of the branch - staging
tag_with_ref: true
# add labels based on the build - see https://github.com/opencontainers/image-spec/blob/master/annotations.md
add_git_labels: true
# push

- 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: Setup Google Cloud CLI
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
version: '286.0.0'
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: |-
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_CLUSTER: dagobah
GKE_ZONE: europe-west1-c
run: |-
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 name=$SERVICE -n staging
kubectl describe pod -l name=$SERVICE -n staging
run: |
kubectl delete pod -l app=$SERVICE -n staging
kubectl describe pod -l app=$SERVICE -n staging
# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM docker.io/maven AS build-env
FROM maven:3.6.3-jdk-8-slim AS build
LABEL description="Wire Roman"
LABEL project="wire-bots:roman"

WORKDIR /app

Expand All @@ -12,7 +14,7 @@ RUN mvn -Dmaven.test.skip=true package

FROM dejankovacevic/bots.runtime:2.10.3

COPY --from=build-env /app/target/roman.jar /opt/roman/
COPY --from=build /app/target/roman.jar /opt/roman/
# COPY target/roman.jar /opt/roman/roman.jar

COPY roman.yaml /etc/roman/
Expand All @@ -21,6 +23,8 @@ COPY roman.yaml /etc/roman/
ARG release_version=development
ENV RELEASE_FILE_PATH=/opt/roman/release.txt
RUN echo $release_version > /opt/roman/release.txt
# TODO - uncomment this when migration to JSON logging is finalized
#ENV APPENDER_TYPE=json-console

WORKDIR /opt/roman

Expand Down
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@
Uses [lithium](https://github.com/wireapp/lithium) to utilize Wire Bot API

### API documentation:
https://proxy.services.wire.com/swagger
[swagger](https://proxy.services.wire.com/swagger#/default)

### Register as Wire Bot Developer
- [register](https://proxy.services.wire.com/swagger#!/default/register)
```
{
"name": "ACME Ltd.",
"email": "[email protected]",
"password": "S3cr3t!"
}
```

### Login
- [login](https://proxy.services.wire.com/swagger#!/default/login)
```
{
"email": "[email protected]",
"password": "S3cr3t!"
}
```

### Create a service
- [create service](https://proxy.services.wire.com/swagger#!/default/create)

```
{
"name": "My Cool Bot",
"url": "https://my.server.com/webhook",
"url": "https://my.server.com/webhook", // Pass _null_ if you prefere websockets
"avatar": "..." // Base64 encoded image
}
```
Expand All @@ -28,16 +41,16 @@ Leave `url` _null_ if you prefer _Websocket_. `avatar` for your bot is optional
After creating your Service the following json is returned:
```
{
"email": "dejan@wire.com",
"company": "ACME",
"service": "ACME Integration",
"email": "acme@email.com",
"company": "ACME Ltd.",
"service": "My Cool Bot",
"service_code": "8d935243-828f-45d8-b52e-cdc1385334fc:d8371f5e-cd41-4528-a2bb-f3feefea160f",
"service_authentication": "g_ZiEfOnMdVnbbpyKIWCVZIk",
"app_key": "..." // Needed when connecting using a websocket
}
```

Go to your Team Settings page and navigate to _Services_ tab. Add this `service_code` and enable this service for your team.
Go to your _Team Settings_ page and navigate to _Services_ tab. Add this `service_code` and enable this service for your team.
Now your team members should be able to see your _Service_ when they open _people picker_ and navigate to _services_ tab.

### Webhook
Expand Down Expand Up @@ -155,7 +168,7 @@ _Outgoing Message_ can be of 4 types:
```
{
"type": "attachment",
"attachment": { ... }
"attachment": { "mimeType" : "image/jpeg", "data" : "..." }
}
```

Expand Down Expand Up @@ -191,8 +204,9 @@ Full description: https://proxy.services.wire.com/swagger#!/default/post
**Note:** `token` that comes with `conversation.init` events is _lifelong_. It should be stored for later usage. `token`
that comes with other event types has lifespan of 20 seconds.

### Bot Example
### Bot Examples
- Echo bot in Java: https://github.com/dkovacevic/demo-proxy
- Poll bot in Kotlin: https://github.com/wireapp/poll-bot

## Build docker image from source code
docker build -t $DOCKER_USERNAME/roman:latest .
Expand Down
Loading

0 comments on commit d37225e

Please sign in to comment.