build runner image #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
push: | |
tags: | |
- "v*" | |
env: | |
FRAMEWORK: net8.0 | |
RUNTIME: linux-x64 | |
CONFIGURATION: Release | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Run tests | |
run: dotnet test --configuration $CONFIGURATION Estimmo.Test/Estimmo.Test.csproj | |
- name: Publish | |
run: dotnet publish -r:$RUNTIME -f:$FRAMEWORK -c:$CONFIGURATION Estimmo.sln | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Postgres image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: docker/postgres | |
file: docker/postgres/Dockerfile | |
tags: ghcr.io/jamie-mh/estimmo-postgres:latest,ghcr.io/jamie-mh/estimmo-postgres:${{ github.ref_name }} | |
- name: Build and push API image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: . | |
file: docker/api/Dockerfile | |
tags: ghcr.io/jamie-mh/estimmo-api:latest,ghcr.io/jamie-mh/estimmo-api:${{ github.ref_name }} | |
- name: Build and push Runner image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: . | |
file: docker/runner/Dockerfile | |
tags: ghcr.io/jamie-mh/estimmo-runner:latest,ghcr.io/jamie-mh/estimmo-runner:${{ github.ref_name }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up SSH | |
run: | | |
mkdir ~/.ssh | |
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy.key | |
chmod 700 ~/.ssh | |
chmod 600 ~/.ssh/deploy.key | |
cat >>~/.ssh/config <<END | |
Host deploy | |
HostName ${{ secrets.DEPLOY_HOST }} | |
User ${{ secrets.DEPLOY_USER }} | |
IdentityFile ~/.ssh/deploy.key | |
StrictHostKeyChecking no | |
ControlMaster auto | |
ControlPath ~/.ssh/control-%C | |
ControlPersist yes | |
END | |
- name: Deploy | |
run: | | |
export DOCKER_HOST=ssh://deploy | |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
# Deploy current tag | |
sed -i 's/estimmo-api:latest/estimmo-api:${{ github.ref_name }}/' compose.yaml | |
sed -i 's/estimmo-postgres:latest/estimmo-postgres:${{ github.ref_name }}/' compose.yaml | |
docker compose -f compose.yaml pull | |
docker compose -f compose.yaml down | |
docker compose -f compose.yaml up --no-deps -d | |
docker image prune -af |