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: CI/CD For docker deploy | |
# Controls when the action will run. | |
on: | |
push: | |
branches: | |
- docker | |
workflow_dispatch: | |
jobs: | |
build-push-docker: | |
runs-on: ubuntu-latest | |
environment: staging | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install SSH key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_SERVER_KEY }} | |
name: id_rsa # optional | |
known_hosts: ${{ secrets.KNOWN_HOSTS }} | |
- name: Deploy to Server | |
run: | | |
BUILD_ARGS="--build-arg NEXT_PUBLIC_VERCEL_URL=preview.statlist.fr --build-arg GITHUB_REDIRECT_URI=https://preview.statlist.fr/api/auth/callback --build-arg NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }} --build-arg SPOTIFY_CLIENT_ID=${{ secrets.SPOTIFY_CLIENT_ID }} --build-arg SPOTIFY_CLIENT_SECRET=${{ secrets.SPOTIFY_CLIENT_SECRET }} --build-arg DEEZER_CLIENT_ID=${{ secrets.DEEZER_CLIENT_ID }} --build-arg DEEZER_CLIENT_SECRET=${{ secrets.DEEZER_CLIENT_SECRET }} --build-arg NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} --build-arg USERNAME=${{ secrets.USERNAME }} --build-arg PASSWORD=${{ secrets.PASSWORD }}" | |
ssh -p $DEPLOY_PORT $DEPLOY_USER@$DEPLOY_DOMAIN << 'EOF' | |
source ~/.zshrc | |
set -e -o errexit | |
cd $DEPLOY_DIR | |
docker network inspect statlist-net >/dev/null 2>&1 || docker network create --driver overlay statlist-net | |
echo 'Login to docker registry...' | |
echo ${{ secrets.DCR_PASSWD }} | docker login --username=kaldray --password-stdin | |
echo 'succesfully logged in to registry docker' | |
echo 'Build with docker (and cache)...🔄' | |
export DOCKER_BUILDKIT=1 | |
cd StatList | |
git checkout $BRANCH_NAME | |
git pull | |
# Build & push docker image | |
docker buildx build --push $BUILD_ARGS -f /docker/prod.Dockerfile -t kaldray/statlist-next:latest ./ | |
echo 'build successful ✅' | |
# Start docker instances | |
echo 'updating docker services...🔄' | |
docker stack deploy --with-registry-auth -c ./docker/docker-compose.prod.yml test | |
echo 'services updated succesfully ✅' | |
EOF | |
env: | |
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} | |
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }} | |
DEPLOY_DOMAIN: ${{ secrets.DEPLOY_DOMAIN }} | |
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |