-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (65 loc) · 2.87 KB
/
cd.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
66
67
68
69
70
71
72
73
74
75
76
77
name: Deploy
on:
push:
branches:
- main
env:
IMAGE_NAME: ${{ github.event.repository.name }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
DB_USER_NAME: ${{ secrets.DB_USER_NAME }} # Add here environment variables first and then when reference it when you build the docker image
DB_USER_PASSWORD: ${{ secrets.DB_USER_PASSWORD }} # Add here environment variables first and then when reference it when you build the docker image
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- 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 }}
- id: lower-repo
name: Repository to lowercase
run: |
echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
- name: Build & push docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64 # Specify the platforms you need
tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
build-args: |
DB_USER_NAME=${{ env.DB_USER_NAME }}
DB_USER_PASSWORD=${{ env.DB_USER_PASSWORD }}
#Add here your environment Variables which you implemented above
file: Dockerfile # Adjust if your Dockerfile is not in the root directory
outputs: digest
- name: Capture WildFly Logs
run: |
docker logs <container_id> | tee wildfly.log
cat wildfly.log
- name: Image digest
run: echo ${{ steps.build-and-push.outputs.digest }}
- uses: appleboy/[email protected]
name: Pull image and start container
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}
script: |
docker container rm -f ${{ env.IMAGE_NAME }} 2> /dev/null || true
docker image rm ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest 2> /dev/null || true
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker pull ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
docker run -d -p 8080:8080 --name ${{ env.IMAGE_NAME }} ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
# Explainaition for the last line:
# docker run -d -p [externalPort]:[internalPort] --name [imageName] ghcr.io/[repositoryOwner]/[repositoryName]:latest