2
0
mirror of https://github.com/offen/website.git synced 2024-12-22 21:10:23 +01:00

build docker images in ci

This commit is contained in:
Frederik Ring 2019-09-09 20:01:22 +02:00
parent 7c4b39e6d6
commit b4e6faff48
7 changed files with 109 additions and 95 deletions

View File

@ -1,16 +1,6 @@
version: 2
production_env: &production_env
environment:
- SERVER_HOST=https://server-alpha.offen.dev
- SCRIPT_HOST=https://script-alpha.offen.dev
- AUDITORIUM_HOST=https://auditorium-alpha.offen.dev
- VAULT_HOST=https://vault-alpha.offen.dev
- HOMEPAGE_HOST=https://www.offen.dev
- NODE_ENV=production
- SECRET_ID_SERVER_CONNECTION_STRING=alpha/server/postgresConnectionString
deploy_preconditions: &deploy_preconditions
build_preconditions: &build_preconditions
requires:
- server
- vault
@ -21,10 +11,12 @@ deploy_preconditions: &deploy_preconditions
branches:
only: /^master$/
build_preconditions: &build_preconditions
deploy_preconditions: &deploy_preconditions
requires:
- build
filters:
branches:
ignore: gh-pages
only: /^master$/
jobs:
server:
@ -156,74 +148,70 @@ jobs:
name: Run tests
command: npm test
deploy_homepage:
build:
docker:
- image: circleci/python:3.6-node
working_directory: ~/offen/homepage
environment:
- SOURCE_BRANCH: master
- TARGET_BRANCH: gh-pages
- image: docker:18-git
working_directory: ~/offen
steps:
- checkout:
path: ~/offen
- checkout
- setup_remote_docker
- restore_cache:
key: offen-homepage-{{ checksum "requirements.txt" }}
- run:
name: Install dependencies
command: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- save_cache:
keys:
- v1-{{ .Branch }}
paths:
- ~/offen/homepage/venv
key: offen-homepage-{{ checksum "requirements.txt" }}
- /caches/proxy.tar
- /caches/server.tar
- run:
name: Install image optimization deps
name: Load Docker image layer cache
command: |
sudo npm install svgo -g
sudo apt-get install libjpeg-progs optipng
set +o pipefail
docker load -i /caches/app.tar | true
- run:
name: Deploy
name: Build application Docker image
command: |
source venv/bin/activate
docker build --cache-from=offen/proxy -t offen/proxy:latest -f build/proxy/Dockerfile .
docker build --cache-from=offen/server -t offen/server:latest -f build/server/Dockerfile .
- run:
name: Save Docker image layer cache
command: |
mkdir -p /caches
docker save -o /caches/proxy.tar offen/proxy
docker save -o /caches/server.tar offen/server
- save_cache:
key: v1-{{ .Branch }}-{{ epoch }}
paths:
- /caches/app.tar
- deploy:
name: Push application Docker image
command: |
echo "$DOCKER_PASS" | docker login --username $DOCKER_USER --password-stdin
docker push offen/server:latest
docker push offen/proxy:latest
git config --global user.email $GH_EMAIL
git config --global user.name $GH_NAME
git clone $CIRCLE_REPOSITORY_URL out
cd out
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
git rm -rf .
cd ..
make publish
cp -a output/. out/.
mkdir -p out/.circleci && cp -a ./../.circleci/. out/.circleci/.
cp CNAME out/CNAME
cd out
git add -A
git commit -m "Automated deployment to GitHub Pages: ${CIRCLE_SHA1}" --allow-empty
git push origin $TARGET_BRANCH
deploy:
working_directory: ~/offen
docker:
- image: circleci/python:3.6
steps:
- checkout
- run:
name: Installing deployment dependencies
command: |
sudo pip install awsebcli --upgrade
- run:
name: Deploying
command: eb deploy staging
workflows:
version: 2
test_build_deploy:
jobs:
- server:
- server
- vault
- script
- auditorium
- packages
- build:
<<: *build_preconditions
- vault:
<<: *build_preconditions
- script:
<<: *build_preconditions
- auditorium:
<<: *build_preconditions
- packages:
<<: *build_preconditions
- deploy_homepage:
- deploy:
<<: *deploy_preconditions

2
.ebignore Normal file
View File

@ -0,0 +1,2 @@
*.*
!Dockerrun.aws.json

View File

@ -0,0 +1,17 @@
branch-defaults:
default:
environment: staging
group_suffix: null
global:
application_name: offen
branch: null
default_ec2_keyname: aws-eb
default_platform: Multi-container Docker 18.06.1-ce (Generic)
default_region: eu-central-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
repository: null
sc: null
workspace_type: Application

31
Dockerrun.aws.json Normal file
View File

@ -0,0 +1,31 @@
{
"AWSEBDockerrunVersion": 2,
"volumes": [],
"containerDefinitions": [
{
"name": "proxy",
"image": "offen/proxy:latest",
"essential": true,
"memory": 128,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80
}
],
"dependsOn": [
{
"containerName": "server",
"condition": "START"
}
],
"links": ["server"]
},
{
"name": "server",
"image": "offen/server:latest",
"essential": true,
"memory": 128
}
]
}

View File

@ -23,8 +23,8 @@ bootstrap:
@docker-compose run server make bootstrap
build:
@docker build -t offen-server:latest -f build/server/Dockerfile .
@docker build -t offen-proxy:latest -f build/proxy/Dockerfile .
@docker build -t offen/server:latest -f build/server/Dockerfile .
@docker build -t offen/proxy:latest -f build/proxy/Dockerfile .
secret:
@docker-compose run server make secret

View File

@ -1,24 +0,0 @@
version: '3'
services:
proxy:
image: offen-proxy:latest
ports:
- 3000:80
depends_on:
- server
server:
image: offen-server:latest
environment:
POSTGRES_CONNECTION_STRING: postgres://postgres:develop@server_database:5432/postgres?sslmode=disable
COOKIE_EXCHANGE_SECRET: Wsttdo4Z3mXV5sTc
EVENT_RETENTION_PERIOD: 4464h
ACCOUNT_USER_EMAIL_SALT: UwBkP24HCUYqy0Eq
depends_on:
- server_database
server_database:
image: postgres:11.2
environment:
POSTGRES_PASSWORD: develop

View File

@ -23,7 +23,7 @@
<link rel="stylesheet" href="/{{ ASSET_URL }}">
{% endassets %}
{% if OFFEN_ACCOUNT_ID %}
<script async src="https://script-alpha.offen.dev/script.js" data-account-id="{{ OFFEN_ACCOUNT_ID }}"></script>
<script async src="/script.js" data-account-id="{{ OFFEN_ACCOUNT_ID }}"></script>
{% endif %}
</head>
<body class="{{page.template}}">