diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 67f59b3c3..cb098e2a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,33 +5,23 @@ on: branches: - main +env: + DOCKER_TAG: ${{ github.sha }} + jobs: - deploy: - name: Build and push Docker images + build-and-push-images: runs-on: ubuntu-latest steps: - - name: Configure PHP - uses: shivammathur/setup-php@v2 + - uses: actions/checkout@v2 + + - name: Login to the Docker registry + uses: docker/login-action@v1 with: - php-version: '7.4' + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Install Workspace - run: | - 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 }} + - run: make build-images + - run: make push-images # vim: sw=2 ts=2 diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..2d56cf2a6 --- /dev/null +++ b/Makefile @@ -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 diff --git a/workspace.yml b/workspace.yml deleted file mode 100644 index 4a2f75de3..000000000 --- a/workspace.yml +++ /dev/null @@ -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 '): - 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 '): - 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 '): - 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