-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (54 loc) · 2.34 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Build and Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
PORTFOLIO_IMAGE_NAME: portfolio
BLOG_IMAGE_NAME: blog
jobs:
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Log into Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Build Portfolio Image
run: docker build portfolio/ --file portfolio/Dockerfile --tag $PORTFOLIO_IMAGE_NAME
- name: Build Blog Image
run: docker build blog/ --file blog/Dockerfile --tag $BLOG_IMAGE_NAME
- name: Log into GitHub Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push Portfolio App Image to GitHub Container Registry
run: |
PORTFOLIO_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$PORTFOLIO_IMAGE_NAME
PORTFOLIO_IMAGE_ID=$(echo $PORTFOLIO_IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
docker tag $PORTFOLIO_IMAGE_NAME $PORTFOLIO_IMAGE_ID:$VERSION
docker push $PORTFOLIO_IMAGE_ID:$VERSION
- name: Push Blog App Image to GitHub Container Registry
run: |
BLOG_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$BLOG_IMAGE_NAME
BLOG_IMAGE_ID=$(echo $BLOG_IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
docker tag $BLOG_IMAGE_NAME $BLOG_IMAGE_ID:$VERSION
docker push $BLOG_IMAGE_ID:$VERSION
- name: Pull Images and Restart Containers on Google Cloud VM
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd portfolio-website
docker-compose down
docker-compose pull
docker-compose up -d