build: add run script
This commit is contained in:
parent
c44b49968f
commit
6a3f3eaa99
4 changed files with 56 additions and 35 deletions
1
.env
Normal file
1
.env
Normal file
|
@ -0,0 +1 @@
|
||||||
|
COMPOSE_PROJECT_NAME=oliverdavies-uk
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
@ -26,8 +26,8 @@ jobs:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- run: make build-images
|
- run: ./run docker:build-images
|
||||||
- run: make push-images
|
- run: ./run docker:push-images
|
||||||
|
|
||||||
- name: Add the deployment SSH key
|
- name: Add the deployment SSH key
|
||||||
uses: shimataro/ssh-key-action@6f350ca8484d8d55c2e361e74d17e638dabe713a # 2.1.0
|
uses: shimataro/ssh-key-action@6f350ca8484d8d55c2e361e74d17e638dabe713a # 2.1.0
|
||||||
|
@ -36,6 +36,6 @@ jobs:
|
||||||
name: id_rsa
|
name: id_rsa
|
||||||
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
|
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
|
||||||
|
|
||||||
- run: make deploy
|
- run: ./run deploy
|
||||||
|
|
||||||
# vim: sw=2 ts=2
|
# vim: sw=2 ts=2
|
||||||
|
|
32
Makefile
32
Makefile
|
@ -1,39 +1,7 @@
|
||||||
COMPOSE_PROJECT_NAME?=oliverdavies-uk
|
|
||||||
DOCKER_WEB_IMAGE_NAME:=ghcr.io/opdavies/$(COMPOSE_PROJECT_NAME)-web
|
|
||||||
|
|
||||||
assets-watch:
|
assets-watch:
|
||||||
npm ci
|
npm ci
|
||||||
npm run watch
|
npm run watch
|
||||||
|
|
||||||
build-images:
|
|
||||||
docker image build . \
|
|
||||||
--file tools/docker/images/Dockerfile \
|
|
||||||
--tag $(DOCKER_WEB_IMAGE_NAME):$(DOCKER_TAG) \
|
|
||||||
--tag $(DOCKER_WEB_IMAGE_NAME):latest \
|
|
||||||
--target=production
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
cd tools/deployment && ansible-playbook deploy.yml
|
|
||||||
|
|
||||||
destroy:
|
|
||||||
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose down --volumes --remove-orphans
|
|
||||||
|
|
||||||
disable:
|
|
||||||
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose down --remove-orphans
|
|
||||||
|
|
||||||
enable:
|
|
||||||
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose up --detach --build --remove-orphans
|
|
||||||
|
|
||||||
ps:
|
|
||||||
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose ps
|
|
||||||
|
|
||||||
push-images:
|
|
||||||
docker image push $(DOCKER_WEB_IMAGE_NAME):$(DOCKER_TAG)
|
|
||||||
docker image push $(DOCKER_WEB_IMAGE_NAME):latest
|
|
||||||
|
|
||||||
run-production:
|
|
||||||
docker-compose --file docker-compose-production.yaml up --detach --remove-orphans
|
|
||||||
|
|
||||||
.PHONY: *
|
.PHONY: *
|
||||||
|
|
||||||
# vim: noexpandtab filetype=make
|
# vim: noexpandtab filetype=make
|
||||||
|
|
52
run
Executable file
52
run
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. .env
|
||||||
|
|
||||||
|
DOCKER_WEB_IMAGE_NAME="ghcr.io/opdavies/${COMPOSE_PROJECT_NAME}-web"
|
||||||
|
|
||||||
|
TTY=""
|
||||||
|
if [[ ! -t 1 ]]; then
|
||||||
|
TTY="-T"
|
||||||
|
fi
|
||||||
|
|
||||||
|
function cmd {
|
||||||
|
# Run any command in the app container.
|
||||||
|
_dc app "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function deploy {
|
||||||
|
cd tools/deployment && ansible-playbook deploy.yml
|
||||||
|
}
|
||||||
|
|
||||||
|
function docker:build-images {
|
||||||
|
docker image build . \
|
||||||
|
--file tools/docker/images/Dockerfile \
|
||||||
|
--tag ${DOCKER_WEB_IMAGE_NAME}:${DOCKER_TAG} \
|
||||||
|
--tag ${DOCKER_WEB_IMAGE_NAME}:latest \
|
||||||
|
--target=production
|
||||||
|
}
|
||||||
|
|
||||||
|
function docker:push-images {
|
||||||
|
docker image push ${DOCKER_WEB_IMAGE_NAME}:${DOCKER_TAG}
|
||||||
|
docker image push ${DOCKER_WEB_IMAGE_NAME}:latest
|
||||||
|
}
|
||||||
|
|
||||||
|
function help {
|
||||||
|
printf "%s <task> [args]\n\nTasks:\n" "${0}"
|
||||||
|
|
||||||
|
compgen -A function | grep -v "^_" | cat -n
|
||||||
|
|
||||||
|
printf "\nExtended help:\n Each task has comments for general usage\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
function run-production {
|
||||||
|
docker-compose --file docker-compose-production.yaml up --detach --remove-orphans
|
||||||
|
}
|
||||||
|
|
||||||
|
function _dc {
|
||||||
|
docker-compose exec ${TTY} "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
eval "${@:-help}"
|
Loading…
Add table
Add a link
Reference in a new issue