From f1a9239ffc1e8ce4acb15ee11a0b9c88ce00f332 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 9 Jul 2021 21:33:03 +0100 Subject: [PATCH] Build and push Docker images using GitHub Actions --- .github/workflows/main.yml | 35 +++++++++++++++++++++++++++++++++++ workspace.yml | 8 ++++++++ 2 files changed, 43 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..390f61e2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +name: Main + +on: + push: + branches: + - main + +jobs: + deploy: + name: Build and push Docker images + runs-on: ubuntu-latest + steps: + - name: Configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + - 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 push $GITHUB_SHA + env: + DOCKER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + DOCKER_REGISTRY_USERNAME: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + +# vim: sw=2 ts=2 diff --git a/workspace.yml b/workspace.yml index 3b82909e..6095a244 100644 --- a/workspace.yml +++ b/workspace.yml @@ -2,6 +2,10 @@ 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('disable'): @@ -35,11 +39,15 @@ command('docker image push '): 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")' + ws docker image build $GIT_COMMIT_SHA 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')