Merge main into production #69
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: pipeline | |
on: | |
push: | |
branches: | |
# - development | |
- production | |
pull_request: | |
branches: | |
# - development | |
- production | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Sanitize repository slug | |
uses: actions/github-script@v6 | |
id: repository_slug | |
with: | |
result-encoding: string | |
script: return '${{ github.repository }}'.toLowerCase() | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
# username: ${{ github.repository_owner }} | |
# password: ${{ secrets.GITHUB_TOKEN }} | |
username: ${{ secrets.GH_CONTAINER_REGISTRY_USER }} | |
password: ${{ secrets.GH_CONTAINER_REGISTRY_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
tags: ghcr.io/${{ steps.repository_slug.outputs.result }}:${{ github.sha }} | |
# test: | |
# needs: build | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Test | |
# run: echo TODO | |
publish: | |
# needs: test | |
needs: build | |
runs-on: ubuntu-latest | |
if: ${{ github.ref == 'refs/heads/production' }} | |
steps: | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
# username: ${{ github.repository_owner }} | |
# password: ${{ secrets.GITHUB_TOKEN }} | |
username: ${{ secrets.GH_CONTAINER_REGISTRY_USER }} | |
password: ${{ secrets.GH_CONTAINER_REGISTRY_TOKEN }} | |
- name: Tag Docker image with branch name | |
run: | | |
DOCKER_IMAGE=ghcr.io/${{ github.repository }} | |
DOCKER_IMAGE=${DOCKER_IMAGE,,} | |
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') | |
docker pull $DOCKER_IMAGE:$GITHUB_SHA | |
docker tag $DOCKER_IMAGE:$GITHUB_SHA $DOCKER_IMAGE:$TAG | |
docker push $DOCKER_IMAGE:$TAG | |
deploy: | |
needs: publish | |
# runs-on: ubuntu-latest | |
runs-on: ubuntu-22.04 | |
if: ${{ github.ref == 'refs/heads/production' }} | |
steps: | |
- name: Deploy to production server | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} | |
SERVER_USER: ${{ secrets.SERVER_USER }} | |
SERVER_HOST: ${{ secrets.SERVER_HOST }} | |
run: | | |
mkdir ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519 | |
chmod 600 ~/.ssh/id_ed25519 | |
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts | |
chmod 644 ~/.ssh/known_hosts | |
eval $(ssh-agent -s) | |
ssh-add ~/.ssh/id_ed25519 | |
ssh $SERVER_USER@$SERVER_HOST "transgenderwachttijd transgenderwachttijd-backend transgenderwachttijd-backend-queue" |