Use Makefile
This commit is contained in:
parent
0a5d933ecf
commit
cd4b23cad4
3 changed files with 47 additions and 91 deletions
36
.github/workflows/main.yml
vendored
36
.github/workflows/main.yml
vendored
|
@ -5,33 +5,23 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
DOCKER_TAG: ${{ github.sha }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
build-and-push-images:
|
||||||
name: Build and push Docker images
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Configure PHP
|
- uses: actions/checkout@v2
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
|
- name: Login to the Docker registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
with:
|
with:
|
||||||
php-version: '7.4'
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Install Workspace
|
- run: make build-images
|
||||||
run: |
|
- run: make push-images
|
||||||
curl \
|
|
||||||
--output ws \
|
|
||||||
--location https://github.com/my127/workspace/releases/download/0.1.3/ws
|
|
||||||
chmod +x ws
|
|
||||||
sudo mv ws /usr/local/bin/ws
|
|
||||||
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Build and push Docker images
|
|
||||||
run: |
|
|
||||||
ws docker image build $GITHUB_SHA
|
|
||||||
ws docker image push $GITHUB_SHA
|
|
||||||
env:
|
|
||||||
DOCKER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
|
||||||
DOCKER_REGISTRY_USERNAME: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
|
|
||||||
|
|
||||||
# vim: sw=2 ts=2
|
# vim: sw=2 ts=2
|
||||||
|
|
34
Makefile
Normal file
34
Makefile
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
COMPOSE_PROJECT_NAME?=oliverdavies-uk
|
||||||
|
DOCKER_IMAGE_NAME:=ghcr.io/opdavies/$(COMPOSE_PROJECT_NAME)-web
|
||||||
|
|
||||||
|
assets-watch:
|
||||||
|
npm ci
|
||||||
|
npm run watch
|
||||||
|
|
||||||
|
build-images:
|
||||||
|
docker image build \
|
||||||
|
--file tools/docker/images/Dockerfile \
|
||||||
|
--target=production \
|
||||||
|
--tag $(DOCKER_IMAGE_NAME):latest \
|
||||||
|
--tag $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) \
|
||||||
|
.
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
cd tools/deployment && ansible-playbook deploy.yml
|
||||||
|
|
||||||
|
disable:
|
||||||
|
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose down
|
||||||
|
|
||||||
|
enable:
|
||||||
|
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose up -d --build
|
||||||
|
|
||||||
|
ps:
|
||||||
|
COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) docker-compose ps
|
||||||
|
|
||||||
|
push-images:
|
||||||
|
docker image push $(DOCKER_IMAGE_NAME):latest
|
||||||
|
docker image push $(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
|
||||||
|
|
||||||
|
.PHONY: *
|
||||||
|
|
||||||
|
# vim: noexpandtab filetype=make
|
|
@ -1,68 +0,0 @@
|
||||||
workspace('oliverdavies-uk'):
|
|
||||||
description: Sculpin website for oliverdavies.uk.
|
|
||||||
|
|
||||||
attribute('docker'):
|
|
||||||
registry:
|
|
||||||
password: "= env('DOCKER_REGISTRY_PASSWORD') ?: ''"
|
|
||||||
url: ghcr.io
|
|
||||||
username: "= env('DOCKER_REGISTRY_USERNAME') ?: ''"
|
|
||||||
repository: ghcr.io/opdavies/oliverdavies-uk-web
|
|
||||||
|
|
||||||
command('deploy'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/tools/deployment)
|
|
||||||
passthru ansible-playbook deploy.yml
|
|
||||||
|
|
||||||
command('disable'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/)
|
|
||||||
run docker-compose down
|
|
||||||
|
|
||||||
command('docker image build <git_commit>'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
GIT_COMMIT_SHA: = input.argument('git_commit')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/)|@
|
|
||||||
run docker image build -f tools/docker/images/Dockerfile --target=production -t @('docker.repository'):${GIT_COMMIT_SHA} .
|
|
||||||
run docker image build -f tools/docker/images/Dockerfile --target=production -t @('docker.repository'):latest .
|
|
||||||
|
|
||||||
command('docker image pull <git_commit>'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
GIT_COMMIT_SHA: = input.argument('git_commit')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/)|@
|
|
||||||
run docker image pull @('docker.repository'):${GIT_COMMIT_SHA}
|
|
||||||
run docker image pull @('docker.repository'):latest
|
|
||||||
|
|
||||||
command('docker image push <git_commit>'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
GIT_COMMIT_SHA: = input.argument('git_commit')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/)|@
|
|
||||||
echo '@("docker.registry.password")' | run docker login --username='@("docker.registry.username")' --password-stdin '@("docker.registry.url")'
|
|
||||||
|
|
||||||
run docker push @('docker.repository'):${GIT_COMMIT_SHA}
|
|
||||||
run docker push @('docker.repository'):latest
|
|
||||||
|
|
||||||
run docker logout '@("docker.registry.url")'
|
|
||||||
|
|
||||||
command('enable'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/)
|
|
||||||
passthru docker-compose up -d --build
|
|
||||||
|
|
||||||
command('ps'):
|
|
||||||
env:
|
|
||||||
COMPOSE_PROJECT_NAME: = @('namespace')
|
|
||||||
exec: |
|
|
||||||
#!bash(workspace:/)
|
|
||||||
passthru docker-compose ps
|
|
Loading…
Add table
Add a link
Reference in a new issue