Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Devops/deploy #8

Merged
merged 40 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e0a6df4
create makefile
titigmr Jun 14, 2021
4fecccc
add app name
titigmr Jun 14, 2021
3fc51ad
add test
titigmr Jun 14, 2021
776c2f0
arm image
titigmr Jun 14, 2021
2d7b738
add lxml
titigmr Jun 15, 2021
2bffb91
action with multiple plateform
titigmr Jun 16, 2021
0f074fe
fix errors on main.yml
titigmr Jun 16, 2021
043deeb
add token GitHub
titigmr Jun 16, 2021
8a3830d
multiplateform arch dockerfile
titigmr Jun 17, 2021
e8d92fc
add build by ARCH
titigmr Jul 24, 2021
2a6db2d
var arch changed
titigmr Jul 24, 2021
618aa4c
var name dev token
titigmr Jul 24, 2021
f58f006
test qemu
titigmr Jul 24, 2021
f12a6df
test armv7
titigmr Jul 24, 2021
9bfb3b3
add matrix ci
titigmr Jul 25, 2021
64cc71c
string matrix
titigmr Jul 25, 2021
19e4893
secret github
titigmr Jul 25, 2021
9f958b9
Add s to secret
titigmr Jul 25, 2021
ba3db30
add name jobs
titigmr Jul 25, 2021
99a4a0a
add owner secret
titigmr Jul 25, 2021
9678f61
add sudo
titigmr Jul 25, 2021
1d7eba3
bash command
titigmr Jul 25, 2021
193bd85
add push ci
titigmr Sep 9, 2021
980e230
add push on release
titigmr Sep 9, 2021
3902296
change version ubuntu
titigmr Sep 9, 2021
bb179ff
add sudo
titigmr Sep 9, 2021
a45df9a
remove quiet
titigmr Sep 9, 2021
c4dc33e
Update docker-compose.yml
titigmr Sep 10, 2021
981a287
Update Makefile
titigmr Sep 10, 2021
08605c1
Update Makefile
titigmr Sep 10, 2021
142ad35
install git
titigmr Sep 10, 2021
4524088
debug
titigmr Sep 10, 2021
c2dd462
remove curl
titigmr Sep 10, 2021
d67fdd4
add version
titigmr Sep 10, 2021
9933754
test
titigmr Sep 10, 2021
b8b5b8d
fetch
titigmr Sep 10, 2021
2f83570
fetch depth 0
titigmr Sep 10, 2021
1c18c44
fetch depth 0
titigmr Sep 10, 2021
c277357
use event_name
titigmr Sep 10, 2021
32b381c
Merge branch 'main' into devops/deploy
titigmr Sep 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.md
.git
*.tar
tmp
.vscode
*.ipynb
__pycache__
docker_save
90 changes: 58 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
name: CI

on:
release:
types: [published]
push:
tags:
- "v*.*.*"
branches:
- master
pull_request:
branches:
- master
release:
# action by user
workflow_dispatch:


jobs:
docker:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- ARCH: armv7l
registry: ghcr.io
username: NAME_OWNER
password: GITHUB_TOKEN
- ARCH: x86_64
registry: docker.io
username: DOCKERHUB_USERNAME
password: DOCKERHUB_TOKEN
name: build ${{ matrix.ARCH }}

steps:
- name: Checkout
- name: Prepare before build
run: |
sudo apt-get update -y

- name: Checkout branch
uses: actions/checkout@v2

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
fetch-depth: 0

- name: Login to ${{ matrix.registry }}
uses: docker/login-action@v1
with:
context: .
platforms: linux/arm/v7
# linux/amd64
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ramoloss:latest

#- name: Run test
# run: |
# ci/test.sh
registry: ${{ matrix.registry }}
username: ${{ secrets[matrix.username] }}
password: ${{ secrets[matrix.password] }}

- name: Build and test on ${{ matrix.ARCH }} plateform
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_DEV_TOKEN }}
run: |
bash ci/build.sh

- name: push on ${{ matrix.registry }} if success on main branch
if: ( success() && github.ref == 'refs/heads/main' )
env:
ARCH: ${{ matrix.ARCH }}
REGISTRY: ${{ matrix.registry }}
REGISTRY_USERNAME: ${{ secrets[matrix.username] }}
run: |
bash ci/push.sh

- name: push latest version on release
if: ( success() && github.event_name == 'release' )
env:
ARCH: ${{ matrix.ARCH }}
REGISTRY: ${{ matrix.registry }}
REGISTRY_USERNAME: ${{ secrets[matrix.username] }}
run: |
make VERSION=latest push
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ __pycache__

# folders
_img_dices

# Pycharm
.idea

# env
.env
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

9 changes: 9 additions & 0 deletions Dockerfile.armv7l
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM arm32v7/python:3.7-buster as arch_armv7l
ENV DISCORD_TOKEN=${DISCORD_TOKEN}
WORKDIR /ramoloss
COPY . .
RUN apt-get update && apt-get install libatlas-base-dev -y \
&& pip install --no-cache-dir -r requirements.txt \
-i https://www.piwheels.org/simple
CMD [ "python", "main.py"]

8 changes: 8 additions & 0 deletions Dockerfile.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.7-buster as x86_64
ENV DISCORD_TOKEN=${DISCORD_TOKEN}
WORKDIR /ramoloss
COPY . .
RUN apt-get update && pip install --no-cache-dir \
-r requirements.txt
CMD [ "python", "main.py"]

88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# repository
SHELL = /bin/bash
NAME ?= ramoloss
ARCH ?= $(shell uname -m)
VERSION := $(shell git describe --abbrev=0)

# docker-compose
DC := $(shell type -p docker-compose)
DC_BUILD_ARGS := --pull --force-rm
DC_RUN_ARGS := -d --no-build
DC_FILE := docker-compose.yml

# docker
#DOCKER_REGISTRY := docker.io
#GITHUB_REGISTRY := ghcr.io
REPOSITORY ?= ramoloss

# image
IMAGE_bot=${NAME}-bot:${VERSION}
IMAGE_REGISTRY_bot=${REGISTRY}/${REGISTRY_USERNAME}/${IMAGE_bot}


export


all:
@echo "Usage: NAME=ramoloss make deploy | build | \
up | down | test | check | push | pull "


# check var or config
check-var-%:
@: $(if $(value $*),,$(error $* is undefined))
@echo ${$*}

check-config:
${DC} -f ${DC_FILE} config

check-config-quiet:
${DC} -f ${DC_FILE} config -q

# build all or one service
build: check-config-quiet
echo ${VERSION}
${DC} -f ${DC_FILE} build ${DC_BUILD_ARGS}

build-%:
@echo "# start $*"
${DC} -f ${DC_FILE} build ${DC_BUILD_ARGS} $*

# up all or one service
up: check-config-quiet
@if [ -z "${DISCORD_TOKEN}" ] ; \
then echo "ERROR: DISCORD_TOKEN \
not defined" ; exit 1 ; fi
${DC} -f ${DC_FILE} up ${DC_RUN_ARGS}

up-%: check-config-quiet
${DC} -f ${DC_FILE} up ${DC_RUN_ARGS} $*

# down all or one service
down:
${DC} -f ${DC_FILE} down

down-%:
${DC} -f ${DC_FILE} down $*

# test
test: test-container
test-%:
@echo "# test $*"
bash tests/test-$*.sh

# push

push: push-bot

push-%:
@if [ -z "${REGISTRY}" -a -z "${REGISTRY_USERNAME}" ] ; \
then echo "ERROR: REGISTRY and REGISTRY_USERNAME \
not defined" ; exit 1 ; fi
docker tag ${IMAGE_$*} ${IMAGE_REGISTRY_$*}
docker push ${IMAGE_REGISTRY_$*}

pull: pull-bot

pull-%:
docker pull
7 changes: 7 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

make build
make up
make test
make down
1 change: 1 addition & 0 deletions ci/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make push
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "",
"command_prefix": "!",
"description": "Très lent et endormi, il lui faut 5 secondes pour ressentir la douleur d'une attaque.",
"extensions": [
"cogs.dice",
"cogs.john",
Expand Down
13 changes: 9 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
discord_bot:
container_name: ramoloss
build: .
version: '3.9'
services:
bot:
environment:
- DISCORD_TOKEN=${DISCORD_TOKEN}
- DISCORD_TOKEN=${DISCORD_TOKEN}
container_name: ${NAME}-bot
image: ${NAME}-bot:${VERSION}
build:
context : .
dockerfile: Dockerfile.${ARCH}
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
discord.py
requests
beautifulsoup4
numpy
opencv-python
matplotlib
pillow
lxml
beautifulsoup4==4.10.0
discord.py==1.7.3
lxml==4.6.3
matplotlib==3.4.3
numpy==1.21.2
opencv-python==4.5.3.56
Pillow==8.3.2
requests==2.26.0
11 changes: 11 additions & 0 deletions tests/test-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

active_container=$(docker ps --filter "name=$APP_NAME" -q)

if [ -z "${active_container}" ]; then
echo "no container is running"
exit 1
else
echo "container $APP_NAME with id $active_container is running"
fi