Refactor/use docker swarm #3
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
# This is a basic workflow to help you get started with Actions | |
name: CI/CD For docker deploy | |
# Controls when the action will run. | |
on: | |
# Triggers the workflow on push or pull request events but only for the main branch | |
pull_request: | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
build-push-docker: | |
runs-on: ubuntu-latest | |
environment: dev | |
steps: | |
- uses: actions/checkout@v2 | |
# - name: Deploy to Server | |
# run: | | |
# echo login from docker...🔄 | |
# echo ${{ secrets.DCR_PASSWD }} | docker login --username=fredkiss3 --password-stdin dcr.fredkiss.dev | |
# echo login succesful ✅ | |
# # Pass env variables | |
# BUILD_ARGS="--build-arg NEXT_PUBLIC_VERCEL_URL=gh.fredkiss.dev --build-arg GITHUB_REDIRECT_URI=https://gh.fredkiss.dev/api/auth/callback --build-arg SESSION_SECRET=${{ secrets.SESSION_SECRET }} --build-arg DATABASE_URL=${{ secrets.POSTGRES_DB_URL }} --build-arg GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} --build-arg GITHUB_SECRET=${{ secrets.GH_SECRET }} --build-arg GITHUB_PERSONAL_ACCESS_TOKEN=${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} --build-arg REDIS_HTTP_URL=${{ secrets.REDIS_HTTP_URL }} --build-arg REDIS_HTTP_USERNAME=${{ secrets.REDIS_HTTP_USERNAME }} --build-arg REDIS_HTTP_PASSWORD=${{ secrets.REDIS_HTTP_PASSWORD }} --build-arg KV_PREFIX=__gh_next__cache_" | |
# # This is the full image name, including the registry | |
# IMAGE="dcr.fredkiss.dev/gh-next" | |
# echo pulling latest image from the registry...🔄 | |
# # Pull an older, existing version from the registry | |
# docker pull ${IMAGE}:dev | |
# echo image pulled in succesfully ✅ | |
# echo Building docker image...🔄 | |
# docker build $BUILD_ARGS --cache-from ${IMAGE}:dev -t ${IMAGE}:dev -t ${IMAGE}:${GITHUB_REF##*/}-${GITHUB_SHA} -f docker/Dockerfile.prod . | |
# echo image built succesfully ✅ | |
- name: Get github branch name | |
id: get-github-ref | |
run: | | |
echo "github_ref=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Cache build output | |
id: next-build-cache | |
uses: actions/cache@v3 | |
with: | |
path: .next/cache | |
key: ${{ runner.os }}-next-build-cache-${{ steps.get-github-ref.outputs.github_ref }} | |
restore-keys: | | |
${{ runner.os }}-next-build-cache-${{ steps.get-github-ref.outputs.github_ref }} | |
- uses: whoan/docker-build-with-cache-action@v5 | |
with: | |
username: fredkiss3 | |
password: ${{ secrets.DCR_PASSWD }} | |
image_name: gh-next | |
image_tag: dev | |
push_git_tag: true | |
registry: dcr.fredkiss.dev | |
dockerfile: docker/Dockerfile.prod | |
context: . | |
build_extra_args: "--build-arg NEXT_PUBLIC_VERCEL_URL=gh.fredkiss.dev --build-arg GITHUB_REDIRECT_URI=https://gh.fredkiss.dev/api/auth/callback --build-arg SESSION_SECRET=${{ secrets.SESSION_SECRET }} --build-arg DATABASE_URL=${{ secrets.POSTGRES_DB_URL }} --build-arg GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} --build-arg GITHUB_SECRET=${{ secrets.GH_SECRET }} --build-arg GITHUB_PERSONAL_ACCESS_TOKEN=${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} --build-arg REDIS_HTTP_URL=${{ secrets.REDIS_HTTP_URL }} --build-arg REDIS_HTTP_USERNAME=${{ secrets.REDIS_HTTP_USERNAME }} --build-arg REDIS_HTTP_PASSWORD=${{ secrets.REDIS_HTTP_PASSWORD }} --build-arg KV_PREFIX=__gh_next__cache_" | |
push_image_and_stages: | | |
ls -l ./.next/cache | |
CONTAINER_ID=$(docker create dcr.fredkiss.dev:dev) | |
# Grab that artifact sweetness | |
docker cp ${CONTAINER_ID}:/app/.next/cache ./.next/cache | |
# Container be gone | |
docker rm ${CONTAINER_ID} | |
# deploy: | |
# # The type of runner that the job will run on | |
# needs: | |
# - build-push-docker | |
# runs-on: ubuntu-latest | |
# environment: dev | |
# # Steps represent a sequence of tasks that will be executed as part of the job | |
# steps: | |
# - uses: actions/checkout@v2 | |
# - 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: | | |
# docker stack deploy --compose-file docker-compose.prod.yaml gh-stack | |
# env: | |
# DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }} | |
# DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} | |
# DEPLOY_DOMAIN: ${{ secrets.DEPLOY_DOMAIN }} | |
# DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
# DCR_PASSWD: ${{ secrets.DCR_PASSWD }} | |
# DCR_USER: ${{ secrets.DCR_USER }} |