Update build-and-upload.yml #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: Build and Upload | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Build Docker image | |
run: docker build -t hngdevops/nextjs-boilerplate:dev -f docker/development/Dockerfile . | |
- name: Save and compress Docker image | |
run: | | |
docker save hngdevops/nextjs-boilerplate:dev > nextjs-dev.tar | |
gzip nextjs-dev.tar | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: docker-image | |
path: nextjs-dev.tar.gz | |
copy-and-load-image: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event.repository.fork == false | |
environment: | |
name: "dev" | |
url: ${{ vars.URL }} | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: docker-image | |
path: . | |
- name: Copy to server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
source: "nextjs-dev.tar.gz" | |
target: "/tmp/nextjs" | |
- name: Load image in server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
script: | | |
cd /tmp/nextjs | |
gunzip nextjs-dev.tar.gz | |
docker load < nextjs-dev.tar | |
rm -f nextjs-dev.tar |