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

Commit

Permalink
Merge pull request #9 from wireapp/github-actions
Browse files Browse the repository at this point in the history
GitHub actions
  • Loading branch information
dkovacevic authored Apr 6, 2020
2 parents 4ff85e0 + b2e1e8d commit 17949f0
Show file tree
Hide file tree
Showing 38 changed files with 353 additions and 368 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gitignore
.travis.yml
Dockerfile
don.iml
.idea/
build/
target/
README.md
script.txt
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI/CD

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set envs
# use latest tag as release version
run: echo ::set-env name=RELEASE_VERSION::${GITHUB_SHA}

- name: Build docker image, publish image as latest if the branch is master
uses: docker/build-push-action@v1
with:
repository: wire-bot/don-bot
# login to repo
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.DOCKER_PASSWORD }}
# pass release_version
build_args: release_version=${{ env.RELEASE_VERSION }}
# build as latest
tags: latest
# 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 master branch
push: ${{ startsWith(github.ref, 'refs/heads/master') }}

# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: Don Bot CI pipeline
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_CI }}
# Send message only if previous step failed
if: failure()
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release Pipeline

on:
release:
types: published

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set envs
# use latest tag as release version
run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF:10}

- name: Build and publish docker image with git tag
uses: docker/build-push-action@v1
with:
repository: wire-bot/don-bot
# login to repo
registry: eu.gcr.io
# see https://github.com/marketplace/actions/docker-build-push#google-container-registry-gcr
username: _json_key
password: ${{ secrets.DOCKER_PASSWORD }}
# 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
push: ${{ startsWith(github.ref, 'refs/tags/') }}

# Send webhook to Wire using Slack Bot
- name: Webhook to Wire
uses: 8398a7/action-slack@v2
with:
status: ${{ job.status }}
author_name: Don Bot Release Pipeline
env:
SLACK_WEBHOOK_URL: ${{ secrets.WEBHOOK_RELEASE }}
# Notify every release
if: always()
24 changes: 22 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
FROM docker.io/maven AS build-env

WORKDIR /app

COPY pom.xml ./

RUN mvn verify --fail-never -U

COPY . ./

RUN mvn -Dmaven.test.skip=true package

FROM dejankovacevic/bots.runtime:2.10.3

COPY target/don.jar /opt/don/don.jar
COPY don.yaml /etc/don/don.yaml
COPY --from=build-env /app/target/don.jar /opt/don/

COPY don.yaml /etc/don/don.yaml

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

WORKDIR /opt/don

EXPOSE 8080 8081 8082

ENTRYPOINT ["java", "-jar", "don.jar", "server", "/etc/don/don.yaml"]
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
mvn package -DskipTests=true -Dmaven.javadoc.skip=true
docker build -t $DOCKER_USERNAME/don-bot:latest .
docker build -t $DOCKER_USERNAME/don-bot:1.2.0 .
docker push $DOCKER_USERNAME/don-bot
kubectl delete pod -l name=don -n prod
kubectl get pods -l name=don -n prod
36 changes: 13 additions & 23 deletions don.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
server:
applicationConnectors:
- type: http
port: 8080

rootPath: /don/*
requestLog:
appenders: []

auth: ${WIRE_SERVICE_TOKEN}
appenders:
- type: console
filterFactories:
- type: status-filter-factory

logging:
level: INFO
loggers:
"com.wire.bots.sdk.tools.logger": INFO
"com.wire.bots.logger": ${LOG_LEVEL:-INFO}

swagger:
resourcePackage: com.wire.bots.sdk.server.resources
uriPrefix: /don
schemes:
- http
- https
auth: ${SERVICE_TOKEN:-}
apiHost: ${WIRE_API_HOST:-https://prod-nginz-https.wire.com}

postgres:
host: localhost
port: 5432
driver: postgresql
user: ${POSTRES_USER}
password: ${POSTRES_PASSWORD}
database:
driverClass: ${DB_DRIVER:-org.postgresql.Driver}
url: ${DB_URL:-jdbc:postgresql://localhost/don}
user: ${DB_USER:-}
password: ${DB_PASSWORD:-}

db:
host: localhost
port: 6379 #redis port
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<artifactId>don</artifactId>
<groupId>com.wire.bots</groupId>
<version>0.6.0</version>
<version>1.2.0</version>

<repositories>
<repository>
Expand All @@ -25,7 +25,12 @@
<dependency>
<groupId>com.wire.bots</groupId>
<artifactId>lithium</artifactId>
<version>2.32.3</version>
<version>2.35.5</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<version>3.2</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -92,4 +97,4 @@
</plugins>
</build>

</project>
</project>
19 changes: 0 additions & 19 deletions script.txt

This file was deleted.

42 changes: 42 additions & 0 deletions src/main/java/com/wire/bots/don/DAO/ServiceDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.wire.bots.don.DAO;

import com.wire.bots.don.DAO.model.Service;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.Define;
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
import org.skife.jdbi.v2.sqlobject.stringtemplate.UseStringTemplate3StatementLocator;
import org.skife.jdbi.v2.tweak.ResultSetMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

@UseStringTemplate3StatementLocator
public interface ServiceDAO {
@SqlUpdate("INSERT INTO Service (Name) VALUES(:name)")
int insertService(@Bind("name") String name);

@SqlQuery("SELECT * FROM Service WHERE Id = :serviceId")
@RegisterMapper(_Mapper.class)
Service getService(@Bind("serviceId") int serviceId);

@SqlUpdate("UPDATE Service SET <column> = :value WHERE id = :serviceId")
int updateService(@Bind("serviceId") int serviceId, @Define("column") String column, @Bind("value") String value);

class _Mapper implements ResultSetMapper<Service> {
@Override
public Service map(int i, ResultSet rs, StatementContext statementContext) throws SQLException {
Service service = new Service();
service.id = rs.getInt("id");
service.name = rs.getString("name");
service.description = rs.getString("description");
service.url = rs.getString("url");
service.profile = rs.getString("profile");
service.serviceId = rs.getString("serviceId");
service.field = rs.getString("field");
return service;
}
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/wire/bots/don/DAO/UserDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.wire.bots.don.DAO;


import com.wire.bots.don.DAO.model.User;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
import org.skife.jdbi.v2.tweak.ResultSetMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;

public interface UserDAO {
@SqlUpdate("INSERT INTO Developer (UserId, Name) VALUES(:userId, :name)")
int insertUser(@Bind("userId") UUID userId, @Bind("name") String name);

@SqlQuery("SELECT * FROM Developer WHERE UserId = :userId")
@RegisterMapper(_Mapper.class)
User getUser(@Bind("userId") UUID userId);

@SqlUpdate("UPDATE Developer SET Email = :email, Provider = :provider WHERE UserId = :userId")
int updateUser(@Bind("userId") UUID userId, @Bind("email") String email, @Bind("provider") String provider);

@SqlUpdate("UPDATE Developer SET cookie = :cookie WHERE UserId = :userId")
int updateCookie(@Bind("userId") UUID userId, @Bind("cookie") String cookie);

@SqlUpdate("UPDATE Developer SET cookie = null WHERE UserId = :userId")
int deleteCookie(@Bind("userId") UUID userId);

class _Mapper implements ResultSetMapper<User> {
@Override
public User map(int i, ResultSet rs, StatementContext statementContext) throws SQLException {
User user = new User();
user.id = (UUID) rs.getObject("UserId");
user.name = rs.getString("name");
user.email = rs.getString("email");
user.provider = rs.getString("provider");
user.cookie = rs.getString("cookie");

return user;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wire.bots.don.db;
package com.wire.bots.don.DAO.model;

public class Service {
public int id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.wire.bots.don.db;
package com.wire.bots.don.DAO.model;

import java.util.UUID;

public class User {
public String id;
public UUID id;
public String name;
public String email;
// public String password;
public String provider;
public String cookie;
}
Loading

0 comments on commit 17949f0

Please sign in to comment.