Merge pull request #10 from anderslatif/master #24
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: Continuous Deployment | |
on: | |
push: | |
# Run workflow every time something is pushed to the main branch | |
branches: | |
- main | |
- master | |
# allow manual triggers for now too | |
workflow_dispatch: | |
manual: true | |
# Remember to set the following secrets in your repository's settings: | |
# https://github.com/your_username/itu-minitwit-ci/settings/secrets/actions | |
# DOCKER_USERNAME | |
# DOCKER_PASSWORD | |
# SSH_USER | |
# SSH_KEY | |
# SSH_HOST | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build and push minitwitimage | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile-minitwit | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/minitwitimage:latest | |
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/minitwitimage:webbuildcache | |
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/minitwitimage:webbuildcache,mode=max | |
- name: Build and push mysqlimage | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile-mysql | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/mysqlimage:latest | |
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/mysqlimage:mysqlbuildcache | |
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/mysqlimage:mysqlbuildcache,mode=max | |
- name: Build and push flagtoolimage | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile-flagtool | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/flagtoolimage:latest | |
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/flagtoolimage:flagtoolbuildcache | |
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/flagtoolimage:flagtoolbuildcache,mode=max | |
- name: Test minitwit | |
run: | | |
docker build -t $DOCKER_USERNAME/minitwittestimage -f Dockerfile-minitwit-tests . | |
yes 2>/dev/null | docker-compose up -d | |
docker run --rm --network=itu-minitwit-network $DOCKER_USERNAME/minitwittestimage | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/do_ssh_key | |
chmod 600 ~/.ssh/do_ssh_key | |
env: | |
SSH_KEY: ${{ secrets.SSH_KEY }} | |
- name: Deploy to server | |
# Configure the ~./bash_profile and deploy.sh file on the Vagrantfile | |
run: > | |
ssh $SSH_USER@$SSH_HOST | |
-i ~/.ssh/do_ssh_key -o StrictHostKeyChecking=no | |
'/minitwit/deploy.sh' | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} |