Skip to content

Sort feed articles by published date #74

Sort feed articles by published date

Sort feed articles by published date #74

Workflow file for this run

name: Build Docker image
on:
push:
branches:
- main
env:
REGISTRY: ghcr.io
APP_IMAGE_NAME: ${{ github.repository }}-app
SERVER_IMAGE_NAME: ${{ github.repository }}-server
SERVICE_NAMES: simple-news-app simple-news-server
jobs:
build-app:
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 app image
uses: docker/build-push-action@v5
with:
target: app
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-app, 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 app
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"