Throw errors from client when response errors #84
This file contains hidden or 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 Docker image | |
on: | |
push: | |
branches: | |
- main | |
env: | |
REGISTRY: ghcr.io | |
APP_IMAGE_NAME: ${{ github.repository }}-web | |
SERVER_IMAGE_NAME: ${{ github.repository }}-server | |
SERVICE_NAMES: reader-web reader-server | |
jobs: | |
build-web: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }} | |
tags: | | |
type=sha, | |
type=raw,value=latest,enable={{is_default_branch}} | |
- name: Build and push web image | |
uses: docker/build-push-action@v5 | |
with: | |
target: web | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-server: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.SERVER_IMAGE_NAME }} | |
tags: | | |
type=sha, | |
type=raw,value=latest,enable={{is_default_branch}} | |
- name: Build and push server image | |
uses: docker/build-push-action@v5 | |
with: | |
target: server | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
deploy: | |
needs: [build-web, build-server] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup SSH | |
env: | |
SSH_USER: ${{ secrets.DEPLOY_USER }} | |
SSH_KEY: ${{ secrets.DEPLOY_KEY }} | |
SSH_HOST: ${{ secrets.DEPLOY_HOST }} | |
SSH_HOST_KEY: ${{ secrets.DEPLOY_HOST_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/staging.key | |
echo "$SSH_HOST_KEY" > ~/.ssh/known_hosts | |
chmod 600 ~/.ssh/staging.key | |
cat >>~/.ssh/config <<END | |
Host deploy_host | |
HostName $SSH_HOST | |
User $SSH_USER | |
IdentityFile ~/.ssh/staging.key | |
StrictHostKeyChecking no | |
END | |
- name: Deploy web | |
env: | |
DOCKER_DIR: ${{ secrets.DOCKER_DIR }} | |
TOKEN: ${{ secrets.DOCKER_REGISTRY_TOKEN }} | |
USER: ${{ secrets.DOCKER_REGISTRY_USER }} | |
run: | | |
ssh deploy_host "cd $DOCKER_DIR && \ | |
docker logout ghcr.io && \ | |
echo $TOKEN | docker login ghcr.io -u $USER --password-stdin && \ | |
docker pull ghcr.io/$APP_IMAGE_NAME:latest && \ | |
docker pull ghcr.io/$SERVER_IMAGE_NAME:latest && \ | |
docker compose up -d $SERVICE_NAMES" |