wip #2
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: Deploy | |
on: | |
push: | |
branches: | |
- next | |
- main | |
- prod | |
workflow_dispatch: | |
jobs: | |
prepare: | |
# Build the matrix of Dockerfiles, looking for all Dockerfiles in deploy/remote | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v2 | |
with: | |
path: source | |
- name: Find Dockerfiles | |
id: set-matrix | |
run: | | |
echo "matrix=$(find ./source/deploy/remote -name 'Dockerfile' -o -name '*.Dockerfile' | jq -R -s -c 'split("\n")[:-1] | map({dockerfile: .})')" >> "$GITHUB_OUTPUT" | |
build: | |
# Build and push every Dockerfile found in the previous step | |
needs: prepare | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: | |
include: ${{fromJson(needs.prepare.outputs.matrix)}} | |
steps: | |
- name: Create image name | |
# Format the Dockerfile name to use it as the image name | |
# Example: ./source/remote/prod/php.Dockerfile -> php | |
id: dockerfile-data | |
run: | | |
echo "image-name=$(basename ${{ matrix.dockerfile }} | sed 's/\.[^.]*$//')" >> "$GITHUB_OUTPUT" | |
- name: Checkout repo | |
uses: actions/checkout@v2 | |
with: | |
path: source | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.DOCKER_REGISTRY }} | |
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} | |
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./source/ | |
file: ${{ matrix.dockerfile }} | |
push: true | |
no-cache: true | |
tags: ${{ secrets.DOCKER_REGISTRY }}/${{ github.repository }}-${{ steps.dockerfile-data.outputs.image-name }}:latest | |
# deploy: | |
# # Deploy the Docker image to the remote server | |
# needs: build | |
# runs-on: ubuntu-22.04 | |
# steps: | |
# - name: Log in to remote server | |
# uses: appleboy/ssh-action@master | |
# with: | |
# host: ${{ secrets.REMOTE_HOST }} | |
# username: ${{ secrets.REMOTE_USER }} | |
# key: ${{ secrets.REMOTE_KEY }} | |
# port: ${{ secrets.REMOTE_PORT }} | |
# script: | | |
# cd ${{ secrets.REMOTE_PATH}} | |
# docker compose pull | |
# docker compose up -d |